-->
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: using where clause when mapping collections
PostPosted: Thu Jun 02, 2005 4:05 pm 
Regular
Regular

Joined: Fri Jan 28, 2005 3:11 am
Posts: 81
Ok, this is a hard question.
I am using version HB 2.1.8, on Oracle 9i.

Take a look at the following mapping:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.talisen.lbwebpo.model">

<class name="Order" table="ORDER">
<id name="orderId" column="ORDER_ID" type="integer">
<generator class="native" />
</id>

<property name="releaseDate" column="RELEASE_DATE" type="timestamp" />
<list name="suppliersRespToLatestRev" inverse="true" cascade="all-delete-orphan" outer-join="false" lazy="false"

where="(supplier_Number, responded_Date) in (select sup.supplier_Number, MAX (sup.responded_Date) from SUPPLIER_TABLE sup, ORDER order where sup.order_Id = order.ORDER_ID and sup.responded_Date &gt; order.RELEASE_DATE group by sup.supplier_Number)">

<key column="ORDER_ID" />
<index column="SUPPLIER_NUMBER"/>
<one-to-many class="com.talisen.lbwebpo.model.OrderResponse"/>
</list>

</class>

</hibernate-mapping>


Now, when I retrieve an Order instance from the database, its suppliersRespToLatestRev property is a list of a whole bunch of null elements, with one OrderResponse element (the one I actually need) at the end. I think I know why that is: when I do "where sup.order_Id = order.ORDER_ID " it gets the rows corresponding to all orders not just to the ones corresponding to the keyed order_id.

Now, you might say, well why not take out the reference to the ORDER all together, since the mapping knows that that’s table everything is being keyed from. The problem is I need the sup.responded_Date > order.RELEASE_DATE, as you can see above.

Any thoughts?


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.