views:

315

answers:

2

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?

+3  A: 

You may be able to do that using native queries. This doc explains.

Vincent Ramdhanie
+3  A: 

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.

ChssPly76