Create custom JPA query function

2019-08-19 04:08发布

问题:

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)

回答1:

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)