diff --git a/documentation/src/main/asciidoc/querylanguage/Expressions.adoc b/documentation/src/main/asciidoc/querylanguage/Expressions.adoc index fd1191cf4f32..a8c2f758361f 100644 --- a/documentation/src/main/asciidoc/querylanguage/Expressions.adoc +++ b/documentation/src/main/asciidoc/querylanguage/Expressions.adoc @@ -1174,8 +1174,8 @@ Finally, the following functions evaluate the id, version, or natural id of an e |=== | Function | Purpose | JPA standard -| `id()` | The value of the entity `@Id` attribute. | ✖ -| `version()` | The value of the entity `@Version` attribute. | ✖ +| `id()` | The value of the entity `@Id` attribute. | ✔ +| `version()` | The value of the entity `@Version` attribute. | ✔ | `naturalid()` | The value of the entity `@NaturalId` attribute. | ✖ | `fk()` | The value of the foreign key column mapped by a `@ManyToOne` (or logical `@OneToOne`) association. Useful with associations annotated `@NotFound`. | ✖ @@ -1207,6 +1207,23 @@ However, we note that the following language constructs work with arrays, and ar | `array includes subarray` | Determine if the elements of one array include all the elements of a second array |=== +[[functions-hash]] +=== Hash functions + +The following functions work on most supported platforms: + +[[hash-functions]] +[cols="12,~,^15"] +|=== +| Function | Purpose | JPA standard + +| `sha()` | The SHA256 hash of a string. | ✖ +| `md5()` | The MD5 hash of a string. | ✖ +|=== + +These functions accept a string and return `byte[]`. +The return value is compatible with the byte array produced by Java's `MessageDigest`. + [[embedding-sql]] ==== Embedding SQL expressions diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index da3a4fb55455..6004ff6a1ed4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -2618,6 +2618,13 @@ public void testSha256Function(SessionFactoryScope scope) { catch (NoSuchAlgorithmException e) { throw new RuntimeException( e ); } + bytes = s.createSelectionQuery("select md5('hello')", byte[].class).getSingleResult(); + try { + assertArrayEquals( MessageDigest.getInstance( "MD5" ).digest("hello".getBytes()), bytes ); + } + catch (NoSuchAlgorithmException e) { + throw new RuntimeException( e ); + } }); } }