I am trying to learn hibernate and faced this issue en route.
I am trying out a many to many mapping. To do so i have created a Category and a Book table. The link table that i have created in cat_books_xref table which simply contains the primary keys of both the tables.
My Mapping are as below:
When i add a new category and a new book everything goes fine. However when i want to add a new book to an existing category the following happens:
1. Category table is not updated, no rows are added. This is expected.
2. New row is added in Book table. Again this is excpected.
3. There should a new row in the link table with the old category id and the newly generated book id. However this is not happening. Instead the existing row is updated with the new bookid.
Have i done something wrong in the mapping.
The code i am using to add a new book to existing category is like below: