Hi guys,
I'm a little new to Hibernate, so thought I would try testing my knowledge by moving some of the hibernate mappings from hb.xml files to java annotations.
I am stuck on one issue, where I want to create a many-to-one relationship from one class, Trade, to another Instrument. However, I don't want to reference the primary key, but a seperate unique column.
In the old mapping (which works), I used:
Code:
<class name="com.....Trade" table="Trade">
........
<many-to-one name="instrument" column="instrumentID" property-ref="instrumentID" class="com.....Instrument"/>
........
</class>
Column 'instrumentID' is not the primary key in the Instrument mapping, but just a normal property (the unique constraint is set at the database level).
In the Trade class, I have annotated as following:
Code:
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE},targetEntity=Instrument.class)
@JoinColumn(name="instrumentID")
public Instrument getInstrument()
{
return instrument;
}
I understand that this means the join column is Trade.instrumentID, but what annotation do I use to show that the column it is linking to is Instrument.instrumentID and not, InstrumentID?
It is throwing this error: 'No row with the given identifier exists: [com.....Instrument#3886092]', I assume because it is looking for something with PK matching 3886092 and not instrumentID.
I have tried various different properties, but each results in an error. Any solution or tutorial link would be well appreciated.
Cheers,
David