-->
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: Order by collection mapping iteration order
PostPosted: Wed Nov 01, 2006 7:59 am 
Newbie

Joined: Thu Oct 12, 2006 9:25 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.0.GA

Name and version of the database you are using:
MySQL 5

Hi Guys,

I'm having some problems with the Iteration order of items in a collection contained in a "parent" object. The hibernate reverse engineering tools generate the foreign key relationship as

Code:
    private Set<Itmm> itmms = new HashSet<Itmm>(0);


which is fine ( and quick ) for items that don't need to be in a specific order, but when I used a query like
Code:
query = entityManager.createQuery("select itmi from Itmi as itmi inner join fetch itmi.itmms as itmmss where itmi.user = ? order by itmi.itmms.itmmCreated desc");
The order by isn't honoured. The sql that is generated does contain the order by clause, but i'm assuming that the collection implementation that is backed onto it doesn't maintain iteration order. I've tried swapping the collection from Set to other types of collection that guarantee, but these generate strange results, e.g when changing to a list, the list contains each item 3 times.

I've searched for forums and google for help with this a great deal, and have found the documentation about mapping files etc, but as i'm using an EJB3 annotations approach, this doesn't seem possible.

To sum up: I need a way of declaring the collection in an object as ordered, so that when I perform an order by on a field of the objects in the collection, the collection maintains the order of insertion.

Anyhelp would be greatly appreciated! many thanks in advance.


[/code]


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.