我可以在hibernate的@Embeddable类中使用@Embedded吗?
示例:A是不同类中的元素集合。
@Embeddable
class A {
@Embedded
B b;
}
@Embeddable
class B {
@Embedded
C c;
}
@Embeddable
class C {
@Embedded
D D;
}
@Embeddable
class D {
}这类东西在hibernate中有效吗?第三层嵌套。
发布于 2013-03-02 07:55:36
是的,在Hibernate中嵌套@Embedded对象是有效的。
直接从文档(http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#d0e714):
@Entity
public class Person {
@Embedded
Address homeAddress;
}
@Embeddable
public class Address {
@Embedded
Country nationality;
}
@Embeddable
public class Country {
...
} (删除额外代码以突出显示嵌套@Embedded)
发布于 2014-10-01 18:54:06
正如johncarl所提到的,这是可能的。要重命名嵌套属性,必须使用'.‘指定整个链。作为分隔符。例如,如果类D具有属性foo,则在类A中,您需要将其重命名为:
@Embedded
@AttributeOverride(name = "c.D.foo", column = @Column(name = "bar"))
B b;https://stackoverflow.com/questions/15168339
复制相似问题