I am trying to map two embeddable objects with a reference to another object (see code) using an existing database:
Code:
@Entity(access=AccessType.FIELD)
public class Article {
@Id
String artnr;
//...more defs
}
@Embeddable(access = AccessType.FIELD)
public class Unit {
@OneToOne
@JoinColumn(name="unit_artnr",referencedColumnName="artnr")
Article article;
Integer amount;
//... more defs
}
@Entity(access = AccessType.FIELD)
public class Order {
@Embedded
@AttributeOverrides({
@AttributeOverride(name="article",column=@Column(name="bunit_artnr")),
@AttributeOverride(name="amount",column=@Column(name="bunit_amount"))
})
Unit bunit;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="article",column=@Column(name="lunit_artnr")),
@AttributeOverride(name="amount",column=@Column(name="lunit_amount"))
})
Unit lunit;
}
The code should finally boil down to this table:
Code:
Table Order
-- ...
bunit_artnr varchar(10),
bunit_amount integer,
lunit_artnr varchar(10),
lunit_amount integer,
-- ...
Instead of this I get the following error from hibernate:
Code:
INFO: processing foreign key constraints
org.hibernate.MappingException: Repeated column in mapping for entity: com.softworks.pronto.model.Order column: unit_artnr (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:550)
As far as I can tell the field name is not correctly substituted when the element is a @OneToOne.
I can remove
lunit, leaving only the single reference to
bunit, in which case the generated sql is incorrect unless I modify the @JoinColumn in
Unit to
Code:
@JoinColumn(name="bunit_artnr")
but this is counterproductive and not what I intend to do.
Any ideas on how to fix this?
Version Info:
annotation-3.1b5