Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding Records into Join Table in a Many-to-Many Relationship Using JPA

 
Black Fox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,

The entity beans generated for MySQL tables by NetBeans do not include join tables used in defining many-to-many relationships.

In my case, the three native tables are 'department', 'quota', and 'dassociate' (dept. assoc.), the latter being a join table. Only entity beans for the first two have been generated, and the information is maintained by JPA through the quotaCollection methods of the bean.

My question is how should I persist a new Quota object so that the appropriate record(s) are inserted into the 'dassociate' table?

What I have been trying to do so far is to persist a Quota object (which works fine), then to getQuotaCollection() from the associated departments, to add the newly created quoatas, and then to setQuotaCollection(newly modified collection that now includes the new quota). Doing this updates the 'quota' table, but no rows are inserted into the 'dassociate' table.
 
Black Fox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Guys!

I cannot believe I couldn't see the departmentCollection methods in the Quota bean! Problem Solved!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic