我有这个类,我试图在Hibernate 3.6.x中映射
@Entity @Table(name = "address") @Inheritance()
public abstract class Address {
@Column(name = "address_type") @Enumerated(EnumType.STRING)
private final AddressType addressType;
@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line1"))})
private final AddressLine addressLine1;
@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line2"))})
private final AddressLine addressLine2;
@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line3"))})
private final AddressLine addressLine3;
@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line4"))})
private final AddressLine addressLine4;
@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line5"))})
private final AddressLine addressLine5;
@Embedded @AttributeOverrides({@AttributeOverride(name = "postcode", column = @Column(name = "postcode"))})
private final Postcode postcode;
}
我收到了这个错误. (我不完全理解 – 有人可以解释一下吗?)
Repeated column in mapping for entity:
Address column: addressLine (should
be mapped with insert=”false” update=”false”)
尽管@Embeddable AddressLine只是一个包装字符串的对象,但我希望保留该类型,以便稍后我可以添加行为/规则.
任何建议允许这种类型的配置?
最佳答案 我没有使用@AttributeOverride但我知道这个错误信息.它是由具有相同名称的列的多个映射引起的,在这种情况下,Hibernate忽略了您的列覆盖定义.
但是,就我而言,我使用的是@ManyToOne类,因此解决方案是@JoinColumns定义覆盖了原始列名.