qin
unread,Jun 11, 2012, 2:41:28 PM6/11/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to beanlib
I have a very complicated object to clone. Basically the object has
many children and grand children and they reference each other. I
can't change that relationship.
While using beanlib to clone the object, I found that when an instance
is referenced at multiple places, it will be cloned multiple times,
which cause problem when persisting the object to database because
hibernate tries to create the same database entry multiple times.
So the solution is to share the same cloned instance at multiple
places where it is referenced.
Here is my changes in
net.sf.beanlib.provider.replicator.BeanReplicator:replicateBean(...):
T to;
+ if (getTargetCloned(from) != null) {
+ // The object (from) is already cloned, and is shared in
multiple places. Don't make a new clone!
+ return (T) getTargetCloned(from);
+ }
try {
to = createToInstance(from, toClass);
} catch (SecurityException e) {
It seems to solve the problem. Now I can clone and persist my object
without problem.
Thanks for beanlib to provide such a useful tool to solve my problem.