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 > 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?
|