I have a search screen using JSF, JBoss Seam and Hibernate at the bottom. There are columns for A, Band C, where the relationships are:
A (1< --; >*) B (1< --; >*) C
Suppose y Ais List< B >and y Bis List< C >(both are one-to-many relationships).
The user interface table supports sorting by any column (ASC or DESC), so I want to sort the query results. For this reason, I used lists in the model.
However, I got an exception that Hibernate cannot willingly receive multiple packages (it considers both lists to be packages). There is an interesting blog here , and they highlight the following solutions:
- Use the @IndexColumn 'annotation (it’s not in my database, and what else, I want the position of the results to be determined in order and not in the index column)
- Get lazy (for performance reasons, I need an impatient receive)
- Change installation list
I changed the list to Set, which, by the way, is more correct according to the model.
- First, if you do not use @OrderBy, the
PersistentSetreturn of Hibernate wraps HashSetthat is out of order. Therefore, when I iterate over it in the user interface, the order is randomly selected, regardless of what the order in the database did. - -, @OrderBy,
PersistentSet LinkedHashSet, , , . OrderBy , , Collections () HQL (). , , , .
Sets SortedSet ( , TreeSet), :
, , , TreeSet ( Comparator, TreeSet ).
, Hibernate @Sort, SortOrder.UNSORTED Comparator. , , , .
.
Maven Google Code. .