You can definitely use any type of database-specific function that you want to use Hibernate HQL (and JPQL if Hibernate is a provider). You just have to tell Hibernate about these features. In 3.3, the only option for this is to provide a custom Dialect and register a function from the Dialect constructor. If you look at the base class of Dialect, you will see many examples of registering functions. It is usually best to extend the exact Dialect that you are currently using and simply provide your extensions (here, by registering the function).
It is interesting to note that Oracle does not classify regexp_like as a function. They classify it as a condition / predicate. I think this is mainly because Oracle SQL does not define the BOOLEAN data type, although it does PL / SQL, and I would set regexp_like as the PL / SQL function returning BOOLEAN ...
Assuming you are currently using Oracle10gDialect, you would do:
public class MyOracle10gDialect extends Oracle10gDialect { public Oracle10gDialect() { super(); registerFunction( "regexp_like", new StandardSQLFunction( "regexp_like", StandardBasicTypes.BOOLEAN ) ); } }
I can't remember if the HQL parser loves functions that return Booleans, but in terms of the fact that it is a predicate in itself. Instead, you can convert true / false to another and check for this:
public class MyOracle10gDialect extends Oracle10gDialect { public Oracle10gDialect() { super(); registerFunction( "regexp_like", new StandardSQLFunction( "regexp_like", StandardBasicTypes.INTEGER ) { @Override public String render( Type firstArgumentType, List arguments, SessionFactoryImplementor factory) { return "some_conversion_from_boolean_to_int(" + super.render( firstArgumentType, arguments, factory ) + ")"; } } ); } }
Steve ebersole
source share