-->
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: Need mapping for a join table
PostPosted: Mon Aug 21, 2006 5:05 pm 
Newbie

Joined: Mon Aug 21, 2006 3:47 pm
Posts: 4
Hi,

This might sound as a newbie question, but I'll post it as I need help.

I have the following tables in an Oracle 10g database and I need mapping for it but somehow can't get it right. I am using Hibernate 3.2.

Order
------
Order_Id
Name


Billing
-------
Billing_Id
Billing_Name
Version


Order_Billing
-------------
Order_Id
Billing_Id
Billing_Version

An Order can have multiple billings with different versions. The current billing is indicated by Order_Billing.Billing_Version. So When I need to look up the billing for an order I run the following SQL:

Select b.Billing_Id, b.Billing_Name from Order o, Billing b, Order_billing ob where
b.billing_id = ob.billing_id and
b.version = ob.billing_version and
o.order_id = ob.order_id and
o.order_id = ?

My mapping in Order.hbm.xml is as follows

<class name="Order" table="Order">

<!-- Other details ommited -->

<set name="billings" table="Order_Billing" lazy="false">
<key column="order_id"/>
<many-to-many column="billing_id" class="billing" />
</set>

The other file Billing.hbm.xml is plain simple file that maps some of the Billing class attributes to columns in the billing table.

Now I am trying to know how can I ask Hibernate to match the version column in the billing table to the billing_version column in the order_billing table (b.version = ob.billing_version clause in the SQL).

I am using a <set> as I'll only be returning 1 billing record at a time, the one indicated by Order_Billing.Billing_Version.

Any help is appreciated.

Thanks,
N


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 7:42 am 
Newbie

Joined: Fri Aug 11, 2006 4:12 am
Posts: 13
Make the (Billing_Id and Version) as the composite primary key and then do the mappings accordingly ...


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.