-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: List Collection having it's order reversed
PostPosted: Tue Jul 19, 2011 12:12 pm 
Newbie

Joined: Mon Jun 23, 2008 11:45 am
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.