本文介绍了休眠方言中用户定义的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函数会引发异常
发布评论