2011-09-09 87 views
4

重複嵌入型我有這個類,我試圖在休眠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; 
} 

我得到這個錯誤映射。 (我不完全理解 - 有人可以解釋一下嗎?)

在實體映射

重複列: 地址欄:addressLine(應 與插入映射=「假」更新=「假」)

儘管@Embeddable AddressLine只是一個包裝字符串的對象,我想保留該類型,以便稍後添加行爲/規則。

任何暗示會允許這種類型的配置?

回答

1

我很慚愧地說,我從這個問題得到的錯誤是由於複製&粘貼犯罪。

儘管不在問題代碼中,但在我的實際代碼庫中,重複的AddressLines 1,2,3和4中的@Column註釋名稱值並未更改爲唯一。

例如 - 這是BAD既是@Column名值是相同的「ADDRESS_LINE1」

@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line1"))}) 
private final AddressLine addressLine1; 

@Embedded @AttributeOverrides({@AttributeOverride(name = "addressLine", column = @Column(name = "address_line1"))}) 
private final AddressLine addressLine2; 

如果所有的列名是獨一無二的,因爲預計本示例將工作。

1

我還沒有使用@AttributeOverride,但我知道這個錯誤消息。這是由同名多列映射引起的,在這種情況下意味着Hibernate忽略了你的列覆蓋定義。

但是,在我的情況下,我使用@ManyToOne類,所以解決方案是@JoinColumns定義覆蓋原始列名稱。