File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
documentation/src/main/asciidoc/querylanguage
hibernate-core/src/main/java/org/hibernate/dialect Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,7 @@ The following special functions make it possible to discover or narrow expressio
576
576
| `cast()` | Narrow a basic type | `cast(x as Type)` | ✔
577
577
| `str()` | Cast to a string | `str(x)` | ✖
578
578
| `ordinal()` | Get the ordinal value of an enum | `ordinal(x)` | ✖
579
+ | `string()` | Get the string-valued name of an enum | `string(x)` | ✖
579
580
|===
580
581
581
582
Let's see what these functions do.
@@ -647,16 +648,17 @@ select str(id) from Order
647
648
648
649
[[function-ordinal]]
649
650
[discrete]
650
- ===== Extracting the ordinal value of an enum
651
+ ===== Extracting the ordinal value or name of an enum
651
652
652
- The function `ordinal(x)` extracts the ordinal value of an enum.
653
- It supports both enum fields mapped as `ORDINAL` and `STRING`.
653
+ The function `ordinal(x)` extracts the ordinal value of an enum, and the function `string(x)` extracts the name of the enum value as a string.
654
654
655
655
[source, hql]
656
656
----
657
- select ordinal(p.type) from Phone p
657
+ select ordinal(p.type), string(p.type) from Phone p
658
658
----
659
659
660
+ Both functions work with enum fields mapped as `ORDINAL` and with enum fields mapped as `STRING`.
661
+
660
662
[[functions-null]]
661
663
==== Functions for working with null values
662
664
Original file line number Diff line number Diff line change @@ -1028,6 +1028,11 @@ public int ordinal() {
1028
1028
* <li> <code>ifnull(arg0, arg1)</code> - synonym of <code>coalesce(a, b)</code>
1029
1029
* </ul>
1030
1030
*
1031
+ * <ul>
1032
+ * <li> <code>ordinal(arg)</code>
1033
+ * <li> <code>string(arg)</code>
1034
+ * </ul>
1035
+ *
1031
1036
* Finally, the following functions are defined as abbreviations for
1032
1037
* <code>extract()</code>, and desugared by the parser:
1033
1038
*
You can’t perform that action at this time.
0 commit comments