Community
Participate
Working Groups
Build Identifier: 2.2.0-M5 Having a relation like: @ManyToMany @JoinTable(name = "JoinTable", joinColumns = @JoinColumn(name = "EntityA_Id", referencedColumnName = "referenceId"), inverseJoinColumns = @JoinColumn(name = "EntityB_Id", referencedColumnName = "id")) public List<EntityB> getEntityBs(){...} class A { int id; // primary key int referenceId; // This is the id of a EntityB } class B { int id; //primary key } // Hope the above is correct as it created from my mind. works during adding of an object but for deleting an object from the list. In the later case the resulting SQL is something like this: DELETE FROM JoinTable WHERE ((EntityB_Id = 40) AND (EntityA_Id= null)) The problem is the 'null' value which is because in foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/mappings/ManyToManyMapping.java in method protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map extraData) throws DatabaseException, OptimisticLockException the call of prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession()) is missing just before AbstractRecord databaseRow = this.mechanism.buildRelationTableSourceAndTargetRow(query.getTranslationRow(), unwrappedObjectDeleted, query.getSession(), this); In all other cases (methods objectOrderChanged...(), insertAddedObject...()) this call is present and at least for the addition I know that it works. I added the mentioned call, compiled a new version, run test (ant test-core-srg, test-core, test-srg, test-lrg) and tested in my application and it works with my application so far (table is empty and SQL statement is correct). No idea about any side-effects etc. Reproducible: Always
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
We've just encountered this issue as well. It generally does NOT work, if the referencedColumnName references non-@Id column of the owning entity. I cannot find anything in JPA 2.1 specification suggesting it should not work and there are even good reasons when it should work. That non-@Id field can be some business unique identifier that was (natural) @Id before and we want to introduce surrogate key as new @Id now. All the other relations shouls still work, but it suddenly stops deleting relations between many-to-many entities. Test case can be run in shell very easily: $ svn export https://github.com/virgo47/litterbin/trunk/issues/eclipselink332309 $ cd eclipselink332309 $ mvn clean package Build fails on running test. Test creates two Dogs and an Owner and adds both dogs to owner.dogs Set (commit). In next transaction it removes one dog from the set and commits again. This produces delete like this: DELETE FROM Owner_Dog WHERE ((dog_id = ?) AND (owner_uniqid = ?)) {1: 1, 2: NULL}; As reported originally in 2010, problem is NULL on owner_uniqid which should have value of owner.uniqId column. In the test I assert that it is NOT null. Delete itself runs happily, but asserting count of dogs for the owner shows the problem. The test itself is on my github: https://github.com/virgo47/litterbin/tree/master/issues/eclipselink332309 svn export is the fastest way how to get it run Also you can switch to hibernate, just comment/uncomment provider lines in persistence.xml and run mvn clean package again - it will pass this time.
BTW: Tested with version 2.6.2
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink