是否可以注册一个用数据库编写并用扩展 hibernate Postgres Dialect 编写的自定义函数,如下所示?在HQL中使用该函数时,接收函数不存在异常。
Postgres函数:
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)"));
我也遇到过类似的问题。问题在于:
该函数是在特定模式中创建的TEST_SCHEMA
。当我使用以下配置时:
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.default_schema">TEST_SCHEMA</property>
I got:
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.
但是,当我在连接 url 中显式指定默认架构时,如下所示
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres?currentSchema=TEST_SCHEMA</property>
我的功能变得可见。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)