-->
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: Using the Where clause in a one-to-many bag collection
PostPosted: Fri Jul 25, 2008 3:38 pm 
Newbie

Joined: Fri Jun 06, 2008 6:25 pm
Posts: 8
I am stumped on how to use the 'Where' clause in a one-to-many bag collection when the select is NOT based in the parent's id column, but rather on another column of the parent.

I have two tables involved: Job (the parent) and JobInfoBTRes (the child collection elements).

The SQL statement should have the meaning of:
Select * from JobInfoBTRes where JobInfoBTRes.bt_pkey = Job.bt_pkey

How do I map the one-to-many relationship?

** I removed some property defnitions for simplicity **

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Framework.Model.Job, Framework" table="Job" lazy="false">
    <id name="id" column="job_pkey" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="BtPKey" column="bt_pkey" not-null="true"/>

    <!-- One-to-many mapping: where [dbo].[Job].[bt_pkey] = [dbo].[JobInfoBTRes].bt_pkey-->
    <bag name="JobInfoBTResList" cascade="all" inverse="true" lazy="false" where="bt_pkey = bt_pkey">
      <key column="bt_pkey" />
      <one-to-many class="Framework.Model.JobInfoBTRes, Framework" />
    </bag>

  </class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Framework.Model.JobInfoBTRes, Framework" table="JobInfoBTRes" lazy="false">
    <id name="PKey" column="Jibd_PKey" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name="BtPKey" column="bt_pkey" not-null="true"/>
    <property name="ShowsOnBook" column="showsonbook" not-null="false"/>
  </class>
</hibernate-mapping>



[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 10:27 am 
Newbie

Joined: Fri Jun 06, 2008 6:25 pm
Posts: 8
Can someone please show me where I can find an example of the usage of the "Where" clause in a mapping?

I could not find any example in the book or the documentation - it just says "put your where clause here", but does not specify how to refer to the tables involved. When I create a where clause that I think should work, I get SQL errors because nHibernate aliases the table names. I just wish the documentation was far more explicit.

Please help.


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.