Forums Register Login

3 tables to one .. one is to many relationship question

+Pie Number of slices to send: Send
Hi I haven't used hibernate for quite some time now and im presented with this situation.


I have 3 tables with different fields but they are all purchase orders and have a set of order_items. (as seen on image) I have a table purchase_order_items which contains all the items of each purchase order may it be type 1,2,3. How do I map this with the hbm.xml .




I should have a one is to many relationship with table to purchase order items , table 2 to purchase order items , table 3 to purchas order items. Is that possible? how do i configure the purchase order item table.

Thanks in advance
+Pie Number of slices to send: Send
Speaking as a non-expert...

One approach would be to introduce a super-type. Have a PurchaseOrder entity that has a one-to-many relationship with OrderItem, and then have three subclasses of PurchaseOrder.

I'm not experienced enough with Hibernate to know how to map that off the top of my head, but I think you could map those entities to those tables using the table-per-concrete class strategy.
+Pie Number of slices to send: Send
Hi thanks for the reply..

im no hibernate expert myself

so this super type has three types of purchase order inside it?

then each types of PO has a one to many to the super type?
+Pie Number of slices to send: Send
Not, inside it - it would have three subclasses (no quite the same thing). But each one of those subtypes would inherit the one-to-many relationship.

Something like this:

When you map that in Hibernate, as I understand it there are three strategies that you can use. You can map them to a single table (using an extra column to indicate the actual type). You can use a table for the superclass, and then extra tables for each subtype (containing any additional fields that you add in the subclass). Or you use table-per-concrete-class, which I think would match the structure you've got.

Edit: here's an example of the mapping.
+Pie Number of slices to send: Send
thanks for the idea. I did somewhat the same thing but what I did was create a Table similar to this one



but had the STUDENT_PHONE table contains more columns of the different types that I needed. it now has ID,SUPPLIER_ID,CUSTOMER_ID,ETC_ID that i now have one to many relationships with the item table.

thanks for the idea sir!

+Pie Number of slices to send: Send
by the way I also used this link in aid of this implementation

Hibernate Tutorial
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1832 times.
Similar Threads
implementation strategy for a simple ordering application.
a modelling problem
HQL query related to many-to-many relationship
ReverseEngineering one-to-many ralationship
Mapping Tables
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:15:16.