JPA: problem with many to many relations
Hi! I'm writing a desktop application using JPA. I have two entities
(User and Movement) with a many to many relation.
This is the part of Movment.java:
private List<User> users;
private List<Movement> movements;
Obviously I have also getters and setters.
users_movements join table has 2 fields: user_id and movment_id.
All seems to work fine, i.e. if I have a record user_id=1 and
movement_id=1 and I assign the movement 1 to user 2 JPA creates a
delete query for 1,1 record and an insert for user_id=2 and
movement_id=1. The problem is when I have a movement associated with 2
users, i.e. movement 1 with user 1 and 2 and I want to delete one of
the two relations: JPA creates a delete query for the relation to
remove, and an insert query for the relation that should remain. The
result is an exception caused by the insert of a duplicate key.
Did I define the relation in the wrong way or did I miss something?
Thanks in advance.
|All times are GMT. The time now is 09:47 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.