想象一下上课
@Embeddable
class A {
@ManyToOne
public B classB;
...
public State someEnum;
}
@Entity
@Table(name = "TEST")
class B {
public long id;
//... some data
@Embedded
@AttributeOverrides({
@AttributeOverride(
name = "classB.id",
column = @Column(name = "EMBEDDED1_ID")
),
@AttributeOverride(
name = "someEnum",
column = @Column(name = "EMBEDDED1_SOMEENUM")
)
})
public A embedded1;
@Embedded
@AttributeOverrides({
@AttributeOverride(
name = "classB.id",
column = @Column(name = "EMBEDDED2_ID")
),
@AttributeOverride(
name = "someEnum",
column = @Column(name = "EMBEDDED2_SOMEENUM")
)
})
public A embedded2;
}
所以我期待数据库表看起来像
- 测试
- ID
- ...
- EMBEDDED1_ID
- EMBEDDED1_SOMEENUM
- EMBEDDED2_ID
- EMBEDDED2_SOMEENUM
但如果失败:
原因:org.hibernate.MappingException:实体映射中的重复列:ClassB 列:classB_id(应使用 insert="false" update="false" 进行映射)
版本:
休眠:5.2.12.FINAL JPA:休眠-jpa-2.1-api