| Summary: | ObjectBuilder copyObject(Object original, CopyGroup copyGroup) copies all mappings even when CASCADE_PRIVATE_PARTS configured | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Doug Clarke <douglas.clarke> |
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P2 | CC: | andrei.ilitchev, eclipselink.foundation-inbox, tom.ware |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
|
Description
Doug Clarke
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 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |