我正在尝试在 hibernate 中使用带有注释的组合。
我有:
@Entity
@Table(name = "Foo")
public class Foo {
private Bar bar;
public void setBar(Bar bar){...}
public Bar getBar() {...)
}
public class Bar {
private double x;
public void setX(double x) {...}
public double getX() {...}
}
当我试图拯救 Foo 时,我得到了
Could not determine type for entity org.bla.Bar at table Foo for columns: [org.hibernate.mapping.Column(bar)]
我尝试在 Bar 上添加 @Entity 注释,但这让我感到困惑:
No identifier specified for entity org.bla.Bar
最佳答案
引用文档的本节描述了该机制:
5.1.5. Embedded objects (aka components)
显然hibernate使用JPA注释来达到这个目的,所以解决方案referred to by Ralph是正确的
简而言之:
如果将类 Address
标记为 @Embeddable
并将 Address
类型的属性添加到类 User
,将属性标记为@Embedded
,那么生成的数据库表User
将具有由Address
指定的所有字段。
请参阅 Ralph 的代码答案。
关于java - Hibernate 中的组合如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284836/