Running a query like this:
Code:
SELECT p.lastname FROM Person p
WHERE SOUNDEX(p.lastname) = SOUNDEX(CAST(? AS STRING))
causes a NullPointerException in the render method of org.hibernate.dialect.function.CastFunction. Reason for this exception is TypeFactory.heuristicType returning null for a type called "STRING":
Code:
public String render(List args, SessionFactoryImplementor factory) throws QueryException {
if ( args.size()!=2 ) {
throw new QueryException("cast() requires two arguments");
}
String type = (String) args.get(1);
int[] sqlTypeCodes = TypeFactory.heuristicType(type).sqlTypes(factory);
...
Replacing "STRING" with "string" in the query cures the problem. As HQL and SQL are case-insensitive most of the time I wonder if it would make sense also to make this function case-insenstive regarding the type parameter. Well, but at least a more meaning-full exception should be thrown, I guess.
Hibernate version:
3.1.3
Mapping documents:
Doesn't matter here I guess.
Code between sessionFactory.openSession() and session.close():
Doesn't matter here I guess.
Full stack trace of any exception that occurs:
Doesn't matter here I guess.
Name and version of the database you are using:
IBM DB/2
The generated SQL (show_sql=true):
None
Debug level Hibernate log excerpt:
Doesn't matter here I guess.