Reputation: 4914
How do I specify a database function in a JPA/Hibernate NamedQuery?
Oddly, hibernate JQL does not recognize the RIGHT function. Without using substring is there a way in hibernate to specify any valid database function in a NamedQuery? I'd prefer not to make it native query or CriteriaQuery.
Upvotes: 3
Views: 1475
Reputation: 42084
JPQL prior JPA 2.1 do not support direct usage of database functions (others than those that get called as consequence of JPQL function in use).
According JPA 2.1 specification functions are invoked as follows:
function_invocation::= FUNCTION(function_name {, function_arg}*)
function_arg ::=
literal |
state_valued_path_expression |
input_parameter |
scalar_expression
In case of RIGHT function it goes like:
FUNCTION("RIGHT, "some_string_possibly_path", 3)
With Hibernate one possibility is to extend dialect as described in this answer.
Upvotes: 3