休眠方言中用户定义的PostgreSQL函数会引发异常

编程入门 行业动态 更新时间:2024-10-18 23:23:05
本文介绍了休眠方言中用户定义的PostgreSQL函数会引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以注册用数据库&用扩展的休眠Postgres方言编写的内容如下?在HQL中使用此功能时,接收功能不存在.

Is it possible to register a custom function written in database & written in extended hibernate Postgres Dialect as follows? Receiving function not exists exception on using this function in HQL.

Postgres函数:

Postgres function:

create or replace function ADD_DAYS(varDate timestamp without time zone, varNumber numeric) returns timestamp without time zone LANGUAGE sql AS $$ SELECT (varDate + varNumber * INTERVAL '1 day') $$;

Java代码:

registerFunction("add_days", new SQLFunctionTemplate(StandardBasicTypes.DATE, "add_days(?1 , ?2)"));

推荐答案

我也遇到过类似的问题.问题出在以下方面:

I have faced with the similar problem. The problem was in the following:

该函数是在特定的模式 TEST_SCHEMA 中创建的.当我使用以下配置时:

The function was created in the particular schema TEST_SCHEMA. When I used the following configuration:

<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property> <property name="hibernate.default_schema">TEST_SCHEMA</property>

我得到了:

org.postgresql.util.PSQLException: ERROR: function levenshtein(character varying, character varying) does not exist. No function matches the given name and argument types. You might need to add explicit type casts.

但是,当我在连接网址中明确指定默认架构时,如下所示

But, when I specified the default schema explicitly in the connection url like below

<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres?currentSchema=TEST_SCHEMA</property>

我的功能可见.

更多推荐

休眠方言中用户定义的PostgreSQL函数会引发异常

本文发布于:2023-10-28 05:11:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   异常   定义   用户   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!