我有以下域类:
@Entity
@Table(name="ADDRESSBOOK_FIELD")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class AbstractAddressbookField {
private int dbID;
private Addressbook addressbook;
public AbstractAddressbookField() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
return dbID;
}
public void setId(int id) {
this.dbID = id;
}
@ManyToOne
@JoinColumn(nullable=false)
public Addressbook getAddressbook() {
return addressbook;
}
public void setAddressbook(Addressbook addressbook) {
this.addressbook = addressbook;
}
}
@Entity
@Table(name="DATE_FIELD")
public class DateField extends AbstractAddressbookField {
public DateField() {
}
}
@Entity
@Table(name="NEW_ADDRESSBOOK")
public class Addressbook {
private int dbID;
private Set<DateField> dateFields = new HashSet<DateField>();
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getDbID() {
return dbID;
}
public void setDbID(int dbID) {
this.dbID = dbID;
}
@OneToMany(mappedBy="Addressbook", cascade={CascadeType.ALL})
public Set<DateField> getDateFields() {
return dateFields;
}
public void setDateFields(Set<DateField> dateFields) {
this.dateFields = dateFields;
}
}
正在正确扫描我的软件包以获取所有映射,但我收到以下异常:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: fields.DateField
我不确定为什么会这样,因为该类已明确映射到。
答案 0 :(得分:1)
看起来该实体未映射到'persistence.xml'文件中。
答案 1 :(得分:1)
我认为你的问题是大写字母:
@OneToMany(mappedBy="Addressbook", cascade={CascadeType.ALL})
public Set<DateField> getDateFields() {
return dateFields;
}
改为使用mappedBy="addressbook
。