-->
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.  [ 4 posts ] 
Author Message
 Post subject: Is it possible to have a default ordering?
PostPosted: Fri Jul 06, 2007 10:21 am 
Newbie

Joined: Fri Oct 27, 2006 8:43 am
Posts: 14
For example, i have a list of X inside Y. X has 5 items, and i insert then in a specific order. Then i save them to Hibernate.

Now i want to recover X from Y, but i have no explicit column to order by and I want to retrieve the collection in the same order i had first inserted (before saving it to the database).

Is it possible? Or i must explicitly order by something?

I can`t order by id, because the items of X already existed in the database, i just want the collection to be in a certain order!

Thanks in advance,
Chicoscience


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 1:04 pm 
Newbie

Joined: Thu Nov 02, 2006 1:15 pm
Posts: 3
This may not be optimal solution, but as a workaround you could use a Map to store your objects by insertion order.

int index = 0;
Map map = new HashMap();

map.put(Integer.valueOf(index), Object o1);
index++;
map.put(Integer.valueOf(index), Object o2);
index++;
etc...

When you need the list of values, you can do map.values()
When you need the insertion order, you can do map.keySet() to get the Integers for each insertion and a map.get(...) for each value.

If someone else has a better suggestion, go with it. That's just my stab at it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:31 am 
Newbie

Joined: Fri Oct 27, 2006 8:43 am
Posts: 14
Thanks a lote, your solution worked, but after that i found an even better solution:

To use @indexColumn for the relation between the entities!

But thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:41 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
Use <list> mapping element instead of set and you'll get ordered list of entities.

_________________
Oleg


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

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.