HI all
i am having huge problems with an OneToMany relationships where both tables have composite keys.
Shortly, ProductLeg has a composite key (ProductLegId) which comprises column LEG_ID and ESMP
UnderlyingXrefImpl has a composite key which comprises property LEG_ID and TYPE.
I am trying to write a OneToMany relationship between ProductLeg and UnderlyingXrefImpl but all i got is this
org.hibernate.AnnotationException: referencedColumnNames(LEG_ID) of com.worldcorpservices.core.domain.esm.UnderlyingXrefImpl.esmUnderlyingXrefs referencing com.worldcorpservices.core.domain.esm.StructuredProductLegImpl not mapped to a single property
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:180)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1318)
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1161)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPro
It WAS working fine when the composite id of UnderlyingXrefImpl had both fields of the primary key of ProductLegImpl (ESMP, LEG_ID).
as i will need to drop ESMP column going forward, i am trying to keep the relationship... but apparently it does not work..
Is this a limitation of HIbernate or JPA? how can i get around it?>
regards
marco
Here are my two classes, with Id included
Code:
@Embeddable
public class ProductLegIdImpl
implements ProductLegId {
private static final long serialVersionUID = 3813072813682475881L;
@Column(name = "LEG_ID")
private final String legId;
@Column(name = "ESMP_ID")
private final String esmp;
......
@Entity
@Table(name = "STRUCTURED_PRODUCT_LEG")
public class ProductLegImpl implements ProductLeg,
Serializable{
private static final long serialVersionUID = -6287099771192357335L;
@EmbeddedId
private ProductLegIdImpl id;
@Column(name = "UNDERLYING_PRICE")
private double underlyingPrice;
@OneToMany(targetEntity=UnderlyingXrefImpl.class,
cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinTable(name="UNDERLYING_XREF",
joinColumns=@JoinColumn(name = "LEG_ID", referencedColumnName = "LEG_ID" )
)
......
@Embeddable
public class UnderlyingXrefIdImpl implements UnderlyingXrefId,
Serializable {
private static final long serialVersionUID = 2080543612340945764L;
@Column(name = "LEG_ID")
private String legId;
@Column(name = "TYPE")
private String type;
@Entity
@Table(name = "UNDERLYING_XREF")
public class UnderlyingXrefImpl implements UnderlyingXref,
Serializable {
private static final long serialVersionUID = -8224391768908346807L;
@EmbeddedId
private UnderlyingXrefIdImpl id;
@Column(name = "VALUE")
private String value;