-->
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: Many-to-many with additional properties
PostPosted: Tue Mar 23, 2010 7:00 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I've got 2 objects: Country and Language
Between these is a many-to-many relation which has additional properties.
So I've made an Object for this relation: CountryNames.

I have the following mappings:
Code:
   <class name="data.Country" table="countries">
      <id name="id" column="id" length="20">
         <generator class="assigned" />
      </id>
   </class>

   <class name="data.Language" table="languages">
      <id name="id" column="id" length="10">
         <generator class="assigned" />
      </id>
   </class>

   <class name="data.CountryName" table="countryNames">
      <composite-id name="fk" class="data.CountryNameFK">
         <key-property name="country" />
         <key-property name="language" />
      </composite-id>

      <many-to-one name="country" class="data.Country" column="country" />
      <many-to-one name="language" class="data.Language" column="language" />
      <property name="name" column="name" />
   </class>

How can I map the connections from Country and Language to CountryName?

And I can't test it yet, but should the foreign key's from CountryName work?


Last edited by aukemid on Wed Mar 24, 2010 6:44 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Collection mapping
PostPosted: Wed Mar 24, 2010 4:57 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Instead of the CountryName mapped above, I also tried the following mapping:
Code:
   <class name="data.CountryName" table="countryNames">
      <composite-id name="fk" class="data.CountryNameFK">
         <key-many-to-one name="country" class="data.Country" column="country" />
         <key-many-to-one name="language" class="data.Language" column="language" />
      </composite-id>

      <property name="name" column="name" />
   </class>

It appears these key-many-to-one's don't work as properties, because when I try to use them I get this error:
Code:
Exception in thread "main" org.hibernate.QueryException: could not resolve property: country of: data.CountryName [FROM data.Country c WHERE c.id IN (SELECT cn.country FROM data.CountryName cn)]


Anyone has a suggestion?


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