Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions documentation/src/main/asciidoc/querylanguage/Expressions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`. | ✖
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
});
}
}
Loading