Search code examples
jakarta-eejpaeclipselinkjpql

Create custom JPA query function


I'm using EclipseLink. Is is possible to use custom query function like:

Select u from User u where my_function(u.name) = my_function(:param)

I would like to retrive entities based on custom created slug names rather than id (and remove any id's from url)


Solution

  • If you implement it as function in database then it is possible, otherwise not (because it translates to SQL in the end anyway calls to method implemented with Java are not possible). Keyword func is used to call database function:

    Select u from User u 
    where func('my_function', u.name) = func('my_function', :param)