Verzeihen Sie mir, da ich Rookie zum Winterschlaf bin und andere Antworten auf ähnliche Fragen dieses Problem nicht ganz behoben (ich bin sicher, mein Problem ist ziemlich einfach). Ich versuche ein OneToMany und ManyToOne Mapping in meinen Persistenzklassen zu haben. Ich habe folgende Tabellen:Verwendung von @OneToMany oder @ManyToMany Targeting auf eine nicht zugeordnete Klasse Ausnahme im Hibernate
city (
id INT AUTO_INCREMENT,
name VARCHAR(255),
)
pincode (
id INT AUTO_INCREMENT,
pincode VARCHAR(6),
city_id INT FOREIGN KEY fk_city_id ON city(id)
)
area (
id INT AUTO_INCREMENT,
name VARCHAR(255),
pincode_id INT FOREIGN KEY fk_pincode_id ON pincode(id)
)
Die folgende Ausdauer Klasse schrieb ich: Für Stadt:
@Table(name="city")
@Entity
City {
@Id
private Integer id;
@Column(name="name")
private String name;
}
Für PinCode:
@Table(name="pincode")
@Entity
PinCode {
@Id
private Integer id;
@Column(name = "pincode")
private String pinCode;
@ManyToOne
@JoinColumn(name = "city_id")
private City city; //Multiple pincodes may be mapped to one city
//One pincode may have multiple areas
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pincode_mapping")
@Fetch(value = FetchMode.SELECT)
private List<Area> area;
}
Für Gebiet:
@Entity
Area {
@Id
private Integer id;
@Column(name = "name")
private String name;
@ManyToOne(fetch = FetchType.EAGER, targetEntity = PinCode.class)
@Column(name = "pincode_id")
private PinCode pinCode; //Multiple areas may be mapped to one pincode
}
Mit Blick auf die folgende Ausnahme:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'sessionFactory' defined in class path resource [applicationContext-resources.xml]: Invocation of init method failed;
nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.mycompany.model.PinCode.area[com.mycompany.model.Area]
Danke. Dies hat das Problem gelöst. –