0
votes

In the documentation of hibernate 4 is following specified:

7.2.2.1. Lists

Lists can be mapped in two different ways:

as ordered lists, where the order is not materialized in the database

as indexed lists, where the order is materialized in the database

To order lists in memory, add @javax.persistence.OrderBy to your property. This annotation takes as parameter a list of comma separated properties (of the target entity) and orders the collection accordingly (eg firstname asc, age desc, weight asc nulls last), if the string is empty, the collection will be ordered by the primary key of the target entity.

I don't understand the note about that "To order lists in memory, add @javax.persistence.OrderBy to your property"

Will be sorting procceed into memory of the DBMS using SQL orderby or into memory of my java application??

If i test it using just simple one to many relationship: (one user has more accounts) with such fragment

@javax.persistence.OrderBy("account-sum ASC, date DESC") // 
    private Set<Account> accounts= new HashSet<>();

The order by clause will be displayed in HQL Statement....

Is it possible to see the generated SQL on base of HQL statement? Thanks a lot for your help:-)

1

1 Answers

0
votes

The sorting will be accomplished by adding an order by clause to the generated SQL so the database will handle the ordering.

Hibernate can be configured to show SQL by setting the hibernate.show_sql configuration property.

See the hibernate documentation for configuring this property.