Hello,
I have made a CompositeUserType (NumberHelper) that consists of two fields (big decimal "value" and string "type"). It works as expected, except when I use it inside an @Embeddable type that is then used more than once inside an entity.
Code:
@Embeddable
public class Benefit implements Serializable {
(...)
// Interval
@Columns(columns = { @Column(name = "intv_from_value"), @Column(name = "intv_from_type") })
@Type(type = "NumberHelper")
NumberValueHelper intv_from;
@Columns(columns = { @Column(name = "intv_to_value"), @Column(name = "intv_to_type") })
@Type(type = "NumberHelper")
NumberValueHelper intv_to;
(...)
}
Code:
@Entity
@TypeDef(name = "NumberHelper", typeClass = NumberHelperUserType.class)
public class Coverage {
(...)
@AttributeOverrides( {
@AttributeOverride(name = "intv_from_type", column = @Column(name = "type_a_intv_from_type")),
@AttributeOverride(name = "intv_from_value", column = @Column(name = "type_a_intv_from_value")),
@AttributeOverride(name = "intv_to_type", column = @Column(name = "type_a_intv_to_type")),
@AttributeOverride(name = "intv_to_value", column = @Column(name = "type_a_intv_to_value")) })
private Benefit benefitTypeA;
@AttributeOverrides( {
@AttributeOverride(name = "intv_from_type", column = @Column(name = "type_b_intv_from_type")),
@AttributeOverride(name = "intv_from_value", column = @Column(name = "type_b_intv_from_value")),
@AttributeOverride(name = "intv_to_type", column = @Column(name = "type_b_intv_to_type")),
@AttributeOverride(name = "intv_to_value", column = @Column(name = "type_b_intv_to_value")) })
private Benefit benefitTypeB;
(...)
}
When I run this, I get:
Quote:
(...)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com...Coverage column: intv_from_value (should be mapped with insert="false" update="false")
I.e. the AttributeOverride isn't applied to column-names inside the @Columns(...) annotation.
This is confirmed by removing one of the "Benefit" fields in "Coverage", in which case it works fine, but the fields are named "intv_*", not "type_a_intv_*" as expected.
Is this a bug or expected? Is there a workaround for this behaviour?
Regards,
Martin