Hibernate:@OneToMany(mappedby =" abstractClass")不起作用

时间:2014-08-07 11:44:23

标签: java hibernate

我的问题:我有抽象的C类,我试图得到一对多的关系:

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "abstractAttachmentObject",targetEntity=Attachment.class)

但我明白了:

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on ********.attachmentObject references an unknown entity: *****************.AbstractAttachmentObject

我尝试过较旧帖子的不同答案,但有人总结说hibernate并不支持这一点。 这个问题现在解决了吗?

代码很长,但我可以解释一下这个主要思想:我有一个名为abstractAttacmentObject的抽象类,它有另外两个继承它的类A和B.这个抽象类应该与类Attachment有一个关系(一对多),其中这些类的一个对象可以有很多附件

`

 @MappedSuperclass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractAttachmentObject extends BaseEntity implements AttachmentObject{

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "abstractAttachmentObject",targetEntity=Attachment.class)
    private List<Attachment> attachments ;
}


@Entity
@Table(name="ATTACHMENT")
public class Attachment extends BaseEntity{
    @ManyToOne
    @JoinColumn(name="attachment_object_id")
    private AbstractAttachmentObject abstractAttachmentObject;
}   

`

0 个答案:

没有答案