Person
class
@Embeddable
public class Person {
@Column
public int code;
//...
}
嵌入在里面Event
两个不同属性的两倍:manager
and operator
@Entity
public class Event {
@Embedded
@Column(name = "manager_code")
public Person manager;
@Embedded
@Column(name = "operator_code")
public Person operator;
//...
}
当使用持久性生成数据库模式时,这应该给出两个相应的列。相反,会抛出异常:
org.hibernate.MappingException:实体映射中的重复列:事件列:代码
如何覆盖默认列名code
对于每个属性?
Use @AttributeOverride https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/AttributeOverride.html,这是一个例子
@Embeddable public class Address {
protected String street;
protected String city;
protected String state;
@Embedded protected Zipcode zipcode;
}
@Embeddable public class Zipcode {
protected String zip;
protected String plusFour;
}
@Entity public class Customer {
@Id protected Integer id;
protected String name;
@AttributeOverrides({
@AttributeOverride(name="state",
column=@Column(name="ADDR_STATE")),
@AttributeOverride(name="zipcode.zip",
column=@Column(name="ADDR_ZIP"))
})
@Embedded protected Address address;
...
}
在你的情况下它看起来像这样
@Entity
public class Event {
@Embedded
@AttributeOverride(name="code", column=@Column(name="manager_code"))
public Person manager;
@Embedded
@AttributeOverride(name="code", column=@Column(name="operator_code"))
public Person operator;
//...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)