Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sujeet sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the code snippets to trace the root cause.
 
Sujeet sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic