开发者

OneToMany Mapping with with Joined Inheritence Annotations:

I have the following domain classes:

@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 A开发者_开发百科ddressbook {
    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;
    }
}

My packages are being scanned correctly to pick up all the mappings, but I am getting the following exception:

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: fields.DateField

I am unsure as to why this is, as the class is clearly mapped to.


Looks like that entity is not mapped in your ' persistence.xml' file.


I think you problem is the capital letter in:

@OneToMany(mappedBy="Addressbook", cascade={CascadeType.ALL})
public Set<DateField> getDateFields() {
   return dateFields;
}

use mappedBy="addressbook instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜