Hi. I'm looking for a quick answer to a (hopefully) simple question to determine whether I need to bother you with the details...
I have a LinkedHashSet<T> Collection (we'll call it 'myOrderedCollection') off of the object that I want deep copied (we'll call it 'myTopLevelObject'). I am using LinkedHashSet to support maintaining the order of the elements in the collection. I am using something like this to accomplish the copy:
HibernateBeanReplicator replicator =
new Hibernate3BeanReplicator().initDetailedBeanPopulatable(myDetailedBeanPopulatableObject)
.initCollectionPropertyNameSet(setProperties)
.initEntityBeanClassSet(setEntityBean);
replicator.copy(myTopLevelObject);
What I am seeing is that the order of the elements in the resulting copy's myOrderedCollection is not the same as that passed in.
Should I expect it to be?
Using beanlib 3.1.1.
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok. I've now tried 3.3.0beta9 with no difference. Is there anything special I should be doing code-wise to tell the system that I want the order preserved?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does the individual element implement Comparable ? Or are you using a Comparator in the Collection ? Do you have a small test case to show the problem ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not using any kind of comparator. I am using an ordered Collection (LinkedHashSet). The data was originally ordered and entered into the original (source) collection via Hibernate order-by. I am looking for the deep copy to maintain the order in the original collection, based on the fact that the original collection provides a predictable iteration order. Maybe that's the key point - it is iteration order I am concerned with. I am looking to have the iteration order preserved from the source to the copy and expected it would be merely based on the fact that I am using the LinkedHashSet for the source collection.
I'll work on a test case, though I may not get to it for a while.
Thanks for your quick responses. For now, it would be great to know if the behavior I am expecting is expected to be working in the latest code-base based on the latest details I've provided.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. I'm looking for a quick answer to a (hopefully) simple question to determine whether I need to bother you with the details...
I have a LinkedHashSet<T> Collection (we'll call it 'myOrderedCollection') off of the object that I want deep copied (we'll call it 'myTopLevelObject'). I am using LinkedHashSet to support maintaining the order of the elements in the collection. I am using something like this to accomplish the copy:
HibernateBeanReplicator replicator =
new Hibernate3BeanReplicator().initDetailedBeanPopulatable(myDetailedBeanPopulatableObject)
.initCollectionPropertyNameSet(setProperties)
.initEntityBeanClassSet(setEntityBean);
replicator.copy(myTopLevelObject);
What I am seeing is that the order of the elements in the resulting copy's myOrderedCollection is not the same as that passed in.
Should I expect it to be?
Using beanlib 3.1.1.
Thanks in advance.
Have you tried the latest beanlib 3.3.0beta9 to see if it works for you ? There has been significant improvement since 3.1.x.
No I haven't tried it. Was initially just hoping to get a quick answer as to whether preserving order is expected to work or not.
It is expected to work only if you are uing 3.3.x.
Ok. I've now tried 3.3.0beta9 with no difference. Is there anything special I should be doing code-wise to tell the system that I want the order preserved?
Does the individual element implement Comparable ? Or are you using a Comparator in the Collection ? Do you have a small test case to show the problem ?
I am not using any kind of comparator. I am using an ordered Collection (LinkedHashSet). The data was originally ordered and entered into the original (source) collection via Hibernate order-by. I am looking for the deep copy to maintain the order in the original collection, based on the fact that the original collection provides a predictable iteration order. Maybe that's the key point - it is iteration order I am concerned with. I am looking to have the iteration order preserved from the source to the copy and expected it would be merely based on the fact that I am using the LinkedHashSet for the source collection.
I'll work on a test case, though I may not get to it for a while.
Thanks for your quick responses. For now, it would be great to know if the behavior I am expecting is expected to be working in the latest code-base based on the latest details I've provided.
I just constructed 2 junit tests on the copy of LinkedHashSet and the order of the elements are preserved alright. See:
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-hibernate-test/src/net/sf/beanlib/hibernate3/HibernateBeanReplicatorTestCollection.java?view=markup
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-test/src/net/sf/beanlib/provider/replicator/CollectionReplicatorTest.java?view=markup
Thanks! That certainly answers the question of whether it's supported. I'll look deeper on my side and see if I can pin down what's going on.