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: Map collection to property
PostPosted: Wed Feb 27, 2008 7:18 pm 
Beginner
Beginner

Joined: Mon Jan 14, 2008 10:58 am
Posts: 24
Hi,
I want to map a collection, not to the primary key, but to a property.
How do I do that?
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="SD.Entities.Client, SD.Entities" table="Client">
      <id name="UniqueIndex" column="UniqueIndex" type="int" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="ClientId" column="ClientID" type="int"/>
      <bag name="Pages" lazy="true" order-by="Title ASC">
         <key column="ClientId"/>
         <one-to-many class="SD.Entities.Page, SD.Entities"/>
      </bag>
   </class>
</hibernate-mapping>


I want to map the bag Client.ClientId == Page.ClientId but now when I run the code it maps Client.UniqueIndex == Page.ClientId

From the other way it works fine, I just use proerty-ref to select correct property.

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="SD.Entities.Page, SD.Entities" table="Page">
      <id name="UniqueIndex" column="UniqueIndex" type="int" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="PageId" column="PageID" type="int"/>
      <many-to-one name="Client" class="SD.Entities.Client, SD.Entities" column="ClientID" property-ref="ClientId" lazy="false" fetch="join" />
   </class>
</hibernate-mapping>


It's the bag that is the problem, it select the wrong pages!
Can I change the bag to something else?


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.