Hibernate deepCopy does not replicate PersistentSet

56 views
Skip to first unread message

Jan Lievens

unread,
Jun 15, 2009, 9:20:18 AM6/15/09
to beanlib
I have the following code:
IdentificatieAangifte identificatieAangifte =
getFromDBviaHibernate();
Class<?>[] entityClasses = {Aangifte.class};
Set<Class<?>> entityClassSet = new HashSet<Class<?>>
(Arrays.asList(entityClasses));
CollectionPropertyName<Aangifte>[] propertyNames =
CollectionPropertyName.createCollectionPropertyNames(Aangifte.class,
new String[]{"feiten"});
Set<CollectionPropertyName<Aangifte>> collectionPropertyNames
= new HashSet<CollectionPropertyName<Aangifte>>();
for (CollectionPropertyName<Aangifte> propertyName :
propertyNames) {
collectionPropertyNames.add(propertyName);
}
Hibernate3BeanReplicator beanReplicator = new
Hibernate3BeanReplicator();
beanReplicator.initDebug(true);
HibernatePropertyFilter hibernatePropertyFilter = new
HibernatePropertyFilter(entityClassSet, collectionPropertyNames,
null);
beanReplicator.initPropertyFilter(hibernatePropertyFilter);
IdentificatieAangifte replica = beanReplicator.deepCopy
(identificatieAangifte, IdentificatieAangifte.class);

Note that IdentificatieAangifte extends Aangifte and that Aangifte has
Set<AangifteFeit> feiten as a member. Even after defining a
HibernatePropertyFilter the Set<AangifteFeit> feiten in my replica-
object is an empty HashSet whereas in the identificatieAangifte-object
it is a org.hibernate.collection.PersitentSet.
Am I doing something wrong here?

Hanson Char

unread,
Jun 15, 2009, 11:35:28 AM6/15/09
to bea...@googlegroups.com
First glance, you should use copy instead of deepCopy if you plug in your own property filter;  See deepCopy javadoc:

"Convenient method to deep copy the given object to an instance of the given class using the default behavior.

Notes:

Use HibernateBeanReplicator.copy(Object, Class) instead of this method if you want to plug in a different (detailed) property filter."

Hanson Char

unread,
Jun 15, 2009, 11:44:06 AM6/15/09
to bea...@googlegroups.com
You may also want to try including AangifteFeit in the entityClassSet to see it that works.
Reply all
Reply to author
Forward
0 new messages