Community
Participate
Working Groups
Starting at Line 1902 of ObjectBuilder the getCloneMappings() call returns all relationship mappings and they are not filered based on their private-owned configuration and the configuration of the CopyGroup. The result is that CASCADE_ALL_PARTS is used instead in all cases where CASCADE_TREE is not used.
The filtering performed in buildCopy method on the mapping: see CollectionMapping and ObjectReferenceMapping.
I am running the following code: TypedQuery<Employee> query = em.createQuery("SELECT e FROM Employee e WHERE e.id IN (SELECT MIN(ee.id) FROM Employee ee)", Employee.class); Employee emp = query.getSingleResult(); System.out.println(">>> Employee retrieved"); // Copy only its names and phone Numbers CopyGroup group = new CopyGroup(); group.cascadePrivateParts(); group.setShouldResetPrimaryKey(true); group.setShouldResetVersion(true); Employee empCopy = (Employee) em.unwrap(JpaEntityManager.class).copy(emp, group); System.out.println(empCopy.getProjects().toString()); The result is that empCopy.projects has a collection where it should not since projects is not a private-owned relationship
Checked into trunk, 2.1.1 is pending. see the patch in Bug 316242 - CopyGroup.CASCADE_TREE does not reset PK values on nested entities In both SimpleSerializeFetchGroupTests and fieldaccess.SimpleSerializeFetchGroupTests added copyWithPk and copyWithoutPk for bug 316242; copyCascadePrivateParts for bug 316241. Also fixed TransactionTests in examples/jpa.employee/eclipselink.example.jpa.employee.testing Note that empCopy.projects still won't be empty - it will rather contain the same objects as the original emp - that's the way the original class ObjectCopyingPolicy always worked, and CopyGroup behaves the same way as ObjectCopyingPolicy (unless in CopyGroup.CASCADE_TREE mode). The only exception to this rule is that by default CopyGroup has shouldResetPrimaryKey set to true, whereas ObjectCopyingPolicy - to false.
Backported to 2.1.1.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink