创建自定义JPA查询功能 [英] Create custom JPA query function

查看:226
本文介绍了创建自定义JPA查询功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EclipseLink。是可以使用自定义查询功能,如:

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


从用户u中选择你的地方my_function(u.name)= my_function(:param)

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

我想基于自定义创建的slug名称而不是id(并从url中删除任何id)来检索实体

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

推荐答案

如果你把它作为函数在数据库中实现那么它是可能的,否则不行(因为它最终会转换为SQL,无论如何调用方法实现用Java是不可能的)。关键字 func 用于调用数据库函数:

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)

这篇关于创建自定义JPA查询功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆