Hibernate SetParameter driving me nuts.

Posted by cbmeeks on Stack Overflow See other posts from Stack Overflow or by cbmeeks
Published on 2011-03-11T16:03:31Z Indexed on 2011/03/11 16:10 UTC
Read the original article Hit count: 518

Filed under:
|

This works

hql = "from State where StateCode like 'T%'";
Query query = session.createQuery(hql);

This does not

hql = "from State where StateCode like :StateCode";
Query query = session.createQuery(hql);
query.setParameter("StateCode", "T%");

I get this

1568 [main] DEBUG org.hibernate.hql.ast.ErrorCounter  - throwQueryException() : no errors
1596 [main] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker  - select << begin [level=1, statement=select]
1608 [main] DEBUG org.hibernate.hql.ast.tree.FromElement  - FromClause{level=1} :  com.kencogroup.kkms.models.State (no alias) -> state0_
1610 [main] DEBUG org.hibernate.hql.ast.tree.FromReferenceNode  - Resolved :  {synthetic-alias} -> {synthetic-alias}
1611 [main] DEBUG org.hibernate.hql.ast.tree.DotNode  - getDataType() : StateCode -> org.hibernate.type.StringType@a39137
1611 [main] DEBUG org.hibernate.hql.ast.tree.FromReferenceNode  - Resolved :  {synthetic-alias}.StateCode -> state0_.StateCode
SELECT Exception: java.lang.reflect.UndeclaredThrowableException

Notice the UndeclaredThrowableException exception.

What am I doing wrong?

The database is SQL Server 2008 if that helps. But like I said, other queries work just fine.

Thanks

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about hql