我可以在休眠的@Embeddable 类中使用@Embedded。
示例:A 是不同类中的元素集合。
@Embeddable
class A {
@Embedded
B b;
}
@Embeddable
class B {
@Embedded
C c;
}
@Embeddable
class C {
@Embedded
D D;
}
@Embeddable
class D {
}
这种东西在休眠中有效吗?第三层嵌套。
我可以在休眠的@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 中嵌套 @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)
正如约翰卡尔所说,这是可能的。为了重命名嵌套属性,您必须使用“。”指定整个链。作为分隔符。例如,如果类 D 具有属性foo,那么在类 A 中,您需要将其重命名为:
@Embedded
@AttributeOverride(name = "c.D.foo", column = @Column(name = "bar"))
B b;