as of revision 405 of ReplicatorTemplate.java,
ReplicatorTemplate.replicate(final Object from, Class<T> toClass)
contains the following
if (unenhanced != from)
toClass = (Class<T>)unenhanced.getClass();
This seems to conflict with the comment for
ReplicatorTemplate.replicate(...) which states:
/**
* Replicate the given from object, recursively if necessary,
* to an instance of the toClass.
*
* Currently a property is replicated if it is an instance
* of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
* JavaBean, or an array.
*/
With the current code toClass is ignored if from is a Hibernate proxy.
Is the above code as intended? Of course I can trivially work around
this by unenhancing the source object before calling replicator.copy
but I'm curious if this is a bug or a necessary part of the bugfix
(duplicate cloning of the same member objects).
Thanks
Donnchadh
Good catch. Can you try to see if the following patch would work
better for you ?
Thanks,
Hanson
--- a/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
+++ b/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
@@ -79,6 +79,10 @@ public abstract class ReplicatorTemplate
* Replicate the given from object, recursively if necessary,
* to an instance of the toClass.
*
+ * If, however, the from object is an enhanced object and the toClass
+ * is the same as the from object's class, the class of the
un-enhanced object
+ * will be used as the toClass instead of the original toClass.
+ *
* Currently a property is replicated if it is an instance
* of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
* JavaBean, or an array.
@@ -94,8 +98,14 @@ public abstract class ReplicatorTemplate
}
final Object unenhanced = unenhanceObject(from);
- if (unenhanced != from)
- toClass = (Class<T>)unenhanced.getClass();
+ if (unenhanced != from
+ && from.getClass() == toClass)
+ { // The original to-class is an enhanced class:
+ // Use the un-enhanced class instead
+ @SuppressWarnings("unchecked")
+ Class<T> unenhancedClass = (Class<T>)unenhanced.getClass();
+ toClass = unenhancedClass;
+ }
if (containsTargetCloned(from))
{ // already transformed
2011/1/11 Donnchadh Ó Donnabháin <donn...@gmail.com>:
Or see the latest source:
Or download it:
Cheers,
Hanson
Donnchadh
I've tried your fix and it seems to work fine. We will test it further
in tonight's build of our system. I'll let you know if we have any
problem with it but it looks good so far.
Thanks again
Donnchadh
2011/1/12 Donnchadh Ó Donnabháin <donn...@gmail.com>: