[英]Hibernate mapping to a class that extends an abstract
I have a superclass for all my db objects.我的所有 db 对象都有一个超类。
@MappedSuperclass
public abstract class DBObject {
@Id
@GeneratedValue
private Long id;
}
But sometimes i want to create a reference to another object by just using the superclass (ie FK through id)但有时我想通过仅使用超类(即 FK 到 id)来创建对另一个对象的引用
@Entity
public class Person extends DBObject {
private DBObject shirt;
}
This gives error: 'Basic' attribute type should not be 'Mapped Superclass'这给出了错误:“基本”属性类型不应为“映射超类”
Basically, the reason for this is, i can have tables for all different kinds of shirts and i would be able to assign whichever one of them to the person.基本上,这样做的原因是,我可以为所有不同类型的衬衫提供桌子,并且我可以将其中的任何一件分配给这个人。
How do i tell hibernate that i dont want to use the DBObject class itself, but a class that extends DBObject我如何告诉 hibernate 我不想使用 DBObject 类本身,而是一个扩展 DBObject 的类
I think you might use following at abstract class:我认为您可能会在抽象类中使用以下内容:
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.