-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: property-ref equivalent with annotations
PostPosted: Thu Sep 11, 2008 8:07 am 
Newbie

Joined: Thu Sep 11, 2008 7:55 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 11:10 am 
Newbie

Joined: Thu Sep 11, 2008 7:55 am
Posts: 2
I am willing to offer credits for a solution to this ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.