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]