The main goal of CascadeTree is to copy only the attributes that have
been explicitly added to the group using addAttribute method.
If you want everything to be copied then it's more convenient to use
cascadeAllParts.
On 8/3/2010 1:44 PM, Kevin Haskett wrote:
In the previous version 2.1.0
using cascadeAllParts was not working, so I had switched to try using
cascadeTree, which was not working broke as you mentioned earlier. In
the nightly build for 2.2 the cascadeTree seems to not populate the
parent object, but I switched back to cascadeAllParts, and that does
seem to be working.
Thanks
org.eclipse.persistence.testing.tests.jpa.fetchgroups.SimpleSerializeFetchGroupTests.copyCascadeAllParts
test seems to be doing the same thing - but can't reproduce the issue:
CopyGroup group = new CopyGroup();
group.cascadeAllParts();
group.setShouldResetPrimaryKey(true);
Employee empCopy = (Employee)
em.unwrap(JpaEntityManager.class).copy(emp, group);
In this test Employee privately owns PhoneNumbers:
public class Employee implements Serializable, Cloneable {
private Collection<PhoneNumber> m_phoneNumbers;
@OneToMany(cascade=ALL, mappedBy="owner")
@PrivateOwned
public Collection<PhoneNumber> getPhoneNumbers() {
return m_phoneNumbers;
}
...
}
public class PhoneNumber implements Serializable {
private Employee owner;
@ManyToOne
@JoinColumn(name="OWNER_ID", referencedColumnName="EMP_ID")
public Employee getOwner() {
return owner;
}
...
}
empCopy has a Collection of copied PhoneNumbers, each of them points
back to empCopy.
May be you could post a simple test case that reproduces the issue.
Thanks,
Andrei
On 8/2/2010 12:30 PM, Kevin Haskett wrote:
I grabbed the latest build from
SVN 7962 and I am still having problems with this. The parent is not
getting set for children after the copy.
Thanks,
Kevin
That's because depth 4 currently is not defined so no copying happens
at all; and depth 3 processed according to the new CASCADE_TREE path
instead of the old CASCADE_ALL_PARTS path.
The only way is to fix CASCADE_TREE value and recompile Eclipselink
On 7/30/2010 3:56 PM, Kevin Haskett wrote:
So instead of hacking the
CopyGroup class I just changed the call from cascadeAllParts() to
setDepth(4);
Unfortunately this is not doing
what I had anticipated. Now after the entityManager.getActiveSession().copy(entity,
copyGroup);
the returned entity is still pointing to the old object tree.
In my case new cpTransaction has
the reference to the previous CpLob, it is not creating a new instance
of it as it had in previous versions.
Thanks,
Kevin
This will be fixed in 2.1.1
The reason for this is my stupid mistake - the newly introduced
CASCADE_TREE constant is equal to preexisting CASCADE_ALL_PARTS.
That causes CASCADE_TREE being performed instead of CASCADE_ALL_PARTS.
Unfortunately there is no workaround.
The only thing you can do is to hack CopyGroup and apply the same fix
2.1.1 does:
substitute:
public static final int CASCADE_TREE = 3;
for:
public static final int CASCADE_TREE = 4;
I apologize for the mess,
Andrei
On 7/30/2010 11:55 AM, Kevin Haskett wrote:
I am having an issue with the CopyGroup using Eclipselink
2.1, not sure when this started showing up as this seemed to work on a
previous version, possibly 1.3?
It is a somewhat large object graph and in previous version
when we used ObjectCopyingPolicy it seemed to copy the
whole object tree and reset the primary keys and then when persisted
would give us a duplicate copy of the whole object tree.
Here is our code now using CopyGroup -
final CopyGroup copyGroup = new CopyGroup();
copyGroup.cascadeAllParts();
copyGroup.setShouldResetPrimaryKey(true);
return (CpTransaction)
entityManager.getActiveSession().copy(entity, copyGroup);
The problem is that it seems to create the whole object tree
but it doesn't set the relationship objects correctly.
Right now the top level object is CpTransaction, with a
relationship to CpLobs
@OneToMany(cascade = CascadeType.ALL, mappedBy =
"cpTransaction")
@PrivateOwned
private Set<CpLob> cpLobs = new HashSet<CpLob>(0);
CpLobs looks like -
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "TRANSACTION_ID", nullable = false)
private CpTransaction cpTransaction;
When I look at the new CpTransaction after the copy it has
the new cpLob item in the HashSet, but the CpLob item's
parent cpTransaction is null. If I leave it at CASCADE_PRIVATE_PARTS,
then it seems to set the cpTransaction parent, but it doesn't seem to
cascade down any further into the object graph than the 2nd Level.
Thanks,
Kevin
This message (including any attachments) is intended only
for the use of the individual or entity to which it is addressed and
may contain information that is non-public, proprietary, privileged,
confidential, and exempt from disclosure under applicable law or may
constitute as attorney work product. If you are not the intended
recipient, you are hereby notified that any use, dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, notify us immediately
by telephone and (i) destroy this message if a facsimile or (ii) delete
this message immediately if this is an electronic communication. Thank
you.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
This message (including any attachments) is intended only for
the use of the individual or entity to which it is addressed and may
contain information that is non-public, proprietary, privileged,
confidential, and exempt from disclosure under applicable law or may
constitute as attorney work product. If you are not the intended
recipient, you are hereby notified that any use, dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, notify us immediately
by telephone and (i) destroy this message if a facsimile or (ii) delete
this message immediately if this is an electronic communication. Thank
you.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
This message (including any attachments) is intended only for
the use of the individual or entity to which it is addressed and may
contain information that is non-public, proprietary, privileged,
confidential, and exempt from disclosure under applicable law or may
constitute as attorney work product. If you are not the intended
recipient, you are hereby notified that any use, dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, notify us immediately
by telephone and (i) destroy this message if a facsimile or (ii) delete
this message immediately if this is an electronic communication. Thank
you.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
This message (including any attachments) is intended only for
the use of the individual or entity to which it is addressed and
may contain information that is non-public, proprietary,
privileged, confidential, and exempt from disclosure under
applicable law or may constitute as attorney work product.
If you are not the intended recipient, you are hereby notified
that any use, dissemination, distribution, or copying of this
communication is strictly prohibited. If you have received this
communication in error, notify us immediately by telephone and
(i) destroy this message if a facsimile or (ii) delete this message
immediately if this is an electronic communication.
Thank you.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|