在JPA / Hibernate NamedQuery中指定数据库函数 [英] Specifying a database function in a JPA/Hibernate NamedQuery

查看:442
本文介绍了在JPA / Hibernate NamedQuery中指定数据库函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JPA / Hibernate NamedQuery中指定数据库函数?



奇怪的是,休眠JQL不能识别RIGHT函数。在没有使用子字符串的情况下,hibernate中有没有一种方法可以在NamedQuery中指定任何有效的数据库函数?我不希望将其设置为原生查询或CriteriaQuery。

解决方案

JPQL JPA 2.1之前不支持直接使用数据库函数(由于使用JPQL功能而被调用的那些人)。根据JPA 2.1规范函数的调用方式如下:

lockquote

function_invocation ::

= FUNCTION(function_name {,function_arg} *)

function_arg :: =

文字|

state_valued_pa​​th_expression |

input_parameter |

scalar_expression

如果使用RIGHT函数,它就像:


$ b $

  FUNCTION(RIGHT,some_string_possibly_path,3)

在Hibernate中,一种可能性是扩展方言,如这个答案。


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.

解决方案

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.

这篇关于在JPA / Hibernate NamedQuery中指定数据库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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