wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate | Many to many mapping | problem in add and delete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate | Many to many mapping | problem in add and delete" Watch "Hibernate | Many to many mapping | problem in add and delete" New topic
Author

Hibernate | Many to many mapping | problem in add and delete

Sujeet sharma
Greenhorn

Joined: Mar 01, 2011
Posts: 6
I have two main tables(account and product) and a junction table account_product which contains thier association. product is kind of my look up table. one account may have multiple products and a product may be associated with many accounts.

account
----------
acct_num
active
---------

product
---------
prod_id
prod_desc
--------

account_product
------------------
acct_num
prod_id
------------------

Following are my requirements -

1. When I add data, data should be added in account table and account_product table but my product table should be untoched, it should work like a lookup table.
2. When I update data, data should be updated in account table and its association table - account_product. For example if product 2,3 are already assoiated with account and now I want to associate product 5,6 only then association of 2,3 should be deleted from account_product table. product table should be untoched.


I am trying many-to many annotation but everything is getting mess-up.
-> On Add/update, lookup table is being updated.

As I am new to hibernate so struggling alot.

Appriciate any help.
Deepak Kumar Jena
Ranch Hand

Joined: Sep 08, 2010
Posts: 68

Post the code snippets to trace the root cause.


dkj4jdk
Sujeet sharma
Greenhorn

Joined: Mar 01, 2011
Posts: 6
Deepak Kumar Jena wrote:Post the code snippets to trace the root cause.


Deepak,

I have doen few changes in my problem statement. Can you please look into it again? I'll post my code soon.

Regards,
Sujeet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate | Many to many mapping | problem in add and delete
 
Similar Threads
Hibernate POJOs -- association or no-association ?
updating association table
Hibernate Association table - extra column
Hibernate Association
Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved