views:

189

answers:

2
+4  A: 

To sort by position, for example, you can use

java.util.Collections.sort(tasks, new Comparator<Task>() {
@Override
public int compare(Task t1, Task t2) {
    return t1.getPosition() - t2.getPosition();
});

Yuval =8-)

Yuval
This is the solution I am now using, thank you very much.
Joshua
+3  A: 

If you want the list order to be preserved by Hibernate, you should probably use <list-index> to map the index column, as described in 6.2.3 Indexed Collections, instead of adding it as field of Task and sorting it yourself.

This way, your Java code doesn't have to worry about the index values at all. The list will be properly sorted when returned by Hibernate, and Hibernate will take care of updating the indexes when the list is modified.

markusk
Ah, finally there it is, the correct solution, though when I try to implement it, the database I already have balks, so I might not implement the real solution this project, though next for certain. :)Thank you!
Joshua