Hibernate Getting Started 14 - Sort with MAP

xiaoxiao2021-03-06  41

Getting Started 14 - Sing from SET and MAP

When you query the SET or MAP member of the object, you can sort it, sorting can be performed at two levels, one is conducted in the Java execution environment, one is the sorting function of the database itself. If you want to sort in the Java execution environment, you can set the sort property in the image file, for example, if set, then set:

By specifying the sort as Natural, Hibernate is loaded with data, the java.utiltedStedSet type object will be used. If it is String, the order is sorted according to the COMPARETO () method, and the above setting will be sorted according to FileName. . If it is MAP, the following settings are set:

The above settings will use java.util.SortedTree, sorted according to Description, and Sort can specify a category name that implements Java.util.comParator in addition to setting NATURAL. The above description is used when querying data, the User category attribute member can be a map or set type, notice that when Sort = "Natural" is set, the properties of the User category are also set when it is set. You must change to sortedMap or sortedset type, such as java.util.treemap or java.util.treeSet, otherwise ClassCasteException will occur. If it is the sort function of the database itself, use the order-by setting sorting, Hibernate uses the SQL statement to sort in the database, such as this setting in SET:

In the same setting in MAP, you can also use the functions in the database, such as:

When using this method, Hibernate uses LinkedHashSet or LinkedHashMap to implement the query, so this method is only available for JDK 1.4 or above.

转载请注明原文地址:https://www.9cbs.com/read-63539.html

New Post(0)