你如何使用Hibernate调用自定义数据库函数? [英] How can you call custom database functions with Hibernate?
问题描述
如果我要在数据库中定义一些函数(可能是Postgres或其他数据库):
创建或替换函数isValidCookie(ckie);
我会从SQL调用它:
select * from cookietable c where isValidCookie(c.cookie);
如何从Hibernate调用这样的自定义函数?
如果你想在HQL中使用你的自定义函数,你需要在合适的方言 PostgreSQLDialect (或任何其他的,真的)源代码,你会看到一堆 registerFunction()调用。您需要为自己的自定义函数添加一个:-) -
然后您必须在Hibernate配置中指定您自己的方言。
If I were to define some function in the database (perhaps Postgres, or any other database):
create or replace function isValidCookie(ckie);
I would call it from SQL as:
select * from cookietable c where isValidCookie(c.cookie);
How can I call a custom function such as this from Hibernate?
If you want to use your custom function in HQL, you'll need to define it in appropriate Dialect
Take a look at PostgreSQLDialect (or any other, really) source, and you'll see a bunch of registerFunction() calls. You'll need to add one more :-) - for your own custom function.
You'll then have to specify your own dialect in Hibernate configuration.
这篇关于你如何使用Hibernate调用自定义数据库函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!