We have a requirement where in we need to use cfg xml instead of annotations for ORM.
We are using hibernate 3 and are stuck on one of the annotations
in TableA:
Code:
@ManyToOne(fetch = FetchType.LAZY,optional=false)
@JoinColumn(name="column1",referencedColumnName="coumn1b")
TableB attributeb;
in TableB:
Code:
@OneToMany(fetch = FetchType.LAZY,mappedBy="attributeb")
private Set<TableA> attributeA;
I have tried doing below in mappings
for TableA
Code:
<many-to-one name="attributeb"
property-ref="column1b"
column="column1"
class="TableB"
lazy="no-proxy"
>
for TableB
Code:
<set name="attributeA"
table="tableA" lazy="no-proxy" inverse="true">
<key>
<column name="column1b" not-null="true"/>
</key>
<one-to-many class="TableA"/>
</Set>
But it's not working. Column1b is not the primary key for TableB, It has a composite primary key. So we want to have a many to one relation on a non-primary column, but its always trying to join to primary key and gives error that not enough attributes passed as primary key.
Could any one suggest correct mapping in XML for such annotations?