List and elements in list is copied when type not specified

8 views
Skip to first unread message

Vegard S. Bye

unread,
Jun 16, 2009, 6:06:40 AM6/16/09
to beanlib
Hi,

Let's say you have bean A that has a bean B.
If you specify which types to copy, and omit B when copying A, B will
not be copied, as expected.
But if A has a java.util.List of B's and do not specify B as a class
to be copied, it gets copied?
Is this a bug, or am I missing something?

I also thought that maybe the list gets copied, but the elements in
the list is the same, i.e. the same objects, but that is not the case,
the B's in the list are also copied to new objects.

Hanson Char

unread,
Jun 16, 2009, 6:59:08 PM6/16/09
to bea...@googlegroups.com
Depends on how you do the copying.  Any sample code ?

Hanson Char

unread,
Jun 16, 2009, 7:32:44 PM6/16/09
to bea...@googlegroups.com
If you use the convenient Hibernate3BeanReplicator, the top level objects of a list is always copied as long as the collection property is somehow specified.  The entityClassSet only affects the object graph within the root objects in the collection.

HTH

Vegard S. Bye

unread,
Jun 17, 2009, 4:06:49 AM6/17/09
to beanlib
I do the copying like this:
HibernateBeanReplicator r = new Hibernate3BeanReplicator(createSet
(VsbBeanLibDataB.class, VsbBeanLibDataC.class, VsbBeanLibDataD.class,
VsbBeanLibDataF.class), null, null);
VsbBeanLibDataA toBean = r.copy(fromBean, VsbBeanLibDataA.class);

And you are correct, if A contains a list of B's and I do not specify
B to be copied it gets copied, but if B contains C's the C's do not
get copied unless C is also specified.
Thanks.


On Jun 17, 1:32 am, Hanson Char <hanson.c...@gmail.com> wrote:
> If you use the convenient Hibernate3BeanReplicator, the top level objects of
> a list is always copied as long as the collection property is somehow
> specified.  The entityClassSet only affects the object graph within the root
> objects in the collection.
>
> HTH
>

Hanson Char

unread,
Jun 17, 2009, 10:03:42 AM6/17/09
to bea...@googlegroups.com
Note "collection name properties" being null means all collection properties will be copied.  Empty means the opposite behavior of no collection properties to be copied.
Reply all
Reply to author
Forward
0 new messages