Hi,
I have a OneToMany relationship in one of my entities that uses a List to hold the associated entities.
Code:
@OneToMany(targetEntity = AccountSqlBean.class, cascade=CascadeType.ALL)
@JoinTable(name="AccountSqlBean_AccountSqlBean", joinColumns = @JoinColumn(name="ID"))
public List<AccountSqlBean> getChildren()
{
return children;
}
The order of the elements in the List are important but I'd read that Hibernate matches the behaviour of the native Java collections well and at first the order of items appeared to be maintained.
However when I attempt to manipulate the order of the collection by removing element at position X and then re-inserting it at position Y, if I restart my program the list order is as expected apart from the fact that the whole element order has been reversed!
I've been searching around the internet and it appears others have had similar issues:
*
https://forum.hibernate.org/viewtopic.php?p=2412202 no answer given
*
http://stackoverflow.com/questions/895121/hibernate-onetomany-list-ordering-persisting-but-reversing there is an answer by KlausMeier here but it seems like a hack that we shouldn't have to do.
Is this a bug in hibernate? Why does the list get reversed when calling the "remove()" and "insert()" methods on a Java list after restart?
If needs be I'll try the hack but it seems like List order should "just work" out of the box.
Thanks,
Tim