antlr.NoViableAltException: unexpected AST node: :

antlr.NoViableAltException: unexpected AST node: :
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4398) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExprLhs(HqlSqlBaseWalker.java:4830) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4311) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1212) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.newValue(HqlSqlBaseWalker.java:1166) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1015) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:729) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:349) [hibernate3.jar:na]
	at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237) [hibernate3.jar:na]
	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251) [hibernate3.jar:na]
	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) [hibernate3.jar:na]
	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134) [hibernate3.jar:na]
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [hibernate3.jar:na]
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate3.jar:na]
	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) [hibernate3.jar:na]
	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) [hibernate3.jar:na]
	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) [hibernate3.jar:na]
	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650) [hibernate3.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_10]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.6.0_10]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_10]
	at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_10]
	at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1293) [spring.jar:2.5.6]
	at $Proxy23.createQuery(Unknown Source) [na:na]

 找了好久,终于试出来了,原来是我的HQL语句有误

 

Query query = session.createQuery("from Article a where a.category.id=:category.id");
query.setInteger("category.id", 1);
q.list();

 

应该把

 

query.setInteger("category.id", 1);
//改为
query.setInteger("categoryId", 1);

 

你可能感兴趣的:(java,spring,Hibernate,orm,sun)