DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Key: NUCJPA-157
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Major Major
Assignee: Unassigned
Reporter: Denis Kramer
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Calling collection setter may loose entities

Created: 24/Nov/11 03:19 PM   Updated: 21/Mar/12 10:18 AM   Resolved: 20/Mar/12 03:49 PM
Component/s: API
Affects Version/s: 3.0.3
Fix Version/s: None

File Attachments: 1. Zip Archive (20 kB)

Environment: Mac OS X 10.7, datanucleus 3.0.3

Datastore: HSQL

 Description  « Hide
Passing a new set to a OneToMany relation setter creates unexpected results if the newly passed collection contains entities that were already part of the relation.

If orphanRemoval is false, these items (already present in old collection) are silently deleted.

If orphanRemoval is true, an exception "Object with id "" is managed by a different Object Manager" is raised.

QuickFix: Customise setter to sync collections in place.

The attached test case contains a JDO implementation that works as expected and a JPA implementation that causes the issues. The described quick fix is also implemented and can be activated via VM parameter -DquickFix=true

Running the test case with "mvn clean test" should result in two failed tests:
* testReplacingChildren(datanucleustest.jpa.TestAddChildrenToEntityA)
* testReplacingDependentChildren(datanucleustest.jpa.TestAddChildrenToEntityA)

Running the test case with "mvn clean test -DquickFix=true" should pass all tests

Denis Kramer added a comment - 24/Nov/11 03:23 PM
The VM parameter to enable the quick fix is actually: -DapplyFix=true

Denis Kramer made changes - 24/Nov/11 03:23 PM
Field Original Value New Value
Attachment [ 11530 ]
Andy Jefferson added a comment - 20/Mar/12 03:49 PM
Presumably this is some side effect of what was fixed in NUCCORE-822, either way I can't reproduce this

Andy Jefferson made changes - 20/Mar/12 03:49 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Duplicate [ 3 ]
Andy Jefferson made changes - 21/Mar/12 10:18 AM
Status Resolved [ 5 ] Closed [ 6 ]