I have this class that I’m trying to map in 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;
}
I’m getting this error. (Which I don’t fully understand – can someone explain it?)
Repeated column in mapping for entity:
Address column: addressLine (should
be mapped with insert=”false” update=”false”)
Although the @Embeddable AddressLine is just a object wrapping a string, I would like to keep the type so I can add behaviour/rules later on.
Any suggests that would allow this type of configuration?
I’m ashamed to say that the error I was getting from this question was due to a copy & paste crime.
Although not in the question code, but in my actual code base, the @Column annotation name value within the duplicated AddressLines 1,2,3, and 4 were not changed to be unique.
For example – This is BAD as both @Column name values are the same of “address_line1”
If all column names are unique this example will work as expected.