cbmeeks
cbmeeks

Reputation: 11420

Hibernate SetParameter driving me nuts

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

Upvotes: 1

Views: 2613

Answers (2)

cbmeeks
cbmeeks

Reputation: 11420

FINALLY!

Turns out, the version of ANTLR in Struts 1 was different than the version of Hibernate. TOTAL confusion.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 692073

If you follow the standard naming conventions, it should be stateCode, and not StateCode. Try with

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

Upvotes: 1

Related Questions