How to repeat the built-in type in sleep mode

I have this class that I am trying to display 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 get this error. (What I don’t quite understand - can someone explain this?)

Duplicate column when matching for an object: Address column: addressLine (should be mapped to insert = "false" update = "false")

Although @Embeddable AddressLine is just an object wrapping a string, I would like to save the type so I can add behavior / rules later.

Any hints that would allow this type of configuration to be used?

+4
source share
2 answers

I am ashamed to say that the error I received from this question was related to the copy and the entry into the crime.

Despite the fact that in the question code, but in my actual code base, the value of the @Column annotation name in the duplicated addresses 1, 2, 3, and 4 was not changed to be unique.

For example, this is BAD because both @Column values ​​are the same for "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; 

If the names of all columns are unique, this example will work as expected.

+1
source

I have not used @AttributeOverride, but I know this error message. This is caused by multiple display of a column with the same name, which in this case means that Hibernate ignored the definition of overriding the column.

However, in my case, I used the @ManyToOne classes, so the solution was @JoinColumns overriding the names of the original columns.

+1
source

All Articles