aspose file tools*
The moose likes Object Relational Mapping and the fly likes Many-to-many probelm help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Many-to-many probelm help" Watch "Many-to-many probelm help" New topic
Author

Many-to-many probelm help

shabarish vai
Ranch Hand

Joined: May 26, 2008
Posts: 79
hi all,
i have an application where you can create category and add products and save to Database.
i have order table and product table where you can create product (all product created goes here) and i also have link table order_product table.
now my problem is if i place a order which has for instance with 2 products i want only order and link table to be saved like,

order table ------ order_product------ product table
1 1 2 1
2 1 3 2
3 2 2 3

so when i submit order I'll have product id's i.e 2,3,2 using these product ID i need to update link table and order table.
is there a way to do this? please help
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Your problem description is not clear to me. Can you
describe the table contents in more detail? Thanks.

Jim ... ...


BEE MBA PMP SCJP-6
shabarish vai
Ranch Hand

Joined: May 26, 2008
Posts: 79
sorry
order table ------
1
2
3
order_product- this is link table with order_id and product_id
1 2
1 3
2 2
product table
1
2
3
wen i submit order i'll have product id's so i need to save product details like order id 1 will have product id 1,2.
shabarish vai
Ranch Hand

Joined: May 26, 2008
Posts: 79
hi can anyone help me in this problem as struck and need it urgently
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Sounds like a basic ManyToMany relationship. Don't see an issue? What ORM are you using?
In JPA you just use a ManyToMany mapping.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
shabarish vai
Ranch Hand

Joined: May 26, 2008
Posts: 79
thanks for the reply the problem here is wen i save order object then order,order_product,product table will be updated i already have product id so only thing i need to update is order,order_product am using hibernate and MSQL, i dont want product table to be updated
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
What do you have so far? Maybe it's time to look at some code.

Jim ... ...
shabarish vai
Ranch Hand

Joined: May 26, 2008
Posts: 79


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Many-to-many probelm help
 
Similar Threads
help regarding EJB-QL
FileReader and FileWriter
JavaScript in Servlets
ordering values in Arraylist
Factory Home Questions