-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-one association to composite id creates faulty FK
PostPosted: Tue Oct 12, 2010 10:43 pm 
Newbie

Joined: Wed May 26, 2010 1:23 pm
Posts: 2
I have a Location class which references a State class with a composite id. The mapping compiles fine, but when I use SchemaExport to create the schema it always gets the foreign key wrong (it compares the Location.state_code to the State.country_id, and the Location.state_country_id to the State.code). I can even go in and fix the FK and then everything works fine...

I would like to find a better way to set up the mapping which will avoid this issue. Here are the condensed mappings:

Also interesting to note is that I couldn't find a way to tell Hibernate how to resolve which properties of State the columns in Location refer to. Basically I can switch the order of the State columns in the Location mapping and the system will change which column it puts the data in; Hibernate is just using the order make a choice. Switching this order does not change the mapping in the foreign key.

<class name="State" table="states">
<composite-id>
<key-many-to-one name="country" class="Country" column="country_id"/>
<key-property name="code"/>
</composite-id>
</class>

<class name="Location" table="locations">
<id name="id" column="id">
<generator class="guid"/>
</id>
<many-to-one name="state" class="State" >
<column name="state_country_id" /> // how does it know which property of State this column refers to?
<column name="state_code"/>
</many-to-one>
</class>

FK ends up trying to compare
locations.state_country_id to state.code,
locations.state_code to state.country_id

Thank you


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.