0
回答
hibernate中的动态HQL报错
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

我想在hibernate中使用动态建立HQL语句查询,并且有嵌套语句,示例如下:

String HQL = "select a.usrName ,a.password from User a where a.id not in :data0 and (a.usrName not in :data20)";
List<String> list = new ArrayList<String>();
		list.add("Boss");
		list.add("admin");
		
		List<String> list1 = new ArrayList<String>();
		list1.add("Boss");
		
		List<String> list3 = new ArrayList<String>();
		list3.add("Boss");
		list3.add("admin");

Session session = HibernateUtil.getSession();
		Query queryObject = session.createQuery(HQL);
		queryObject.setParameterList("data0", list);
		queryObject.setParameterList("data20", list3);

List<Object []> objects = queryObject.list();
		for(Object [] objects2 :objects){
			for(Object object : objects2){
				System.out.print(object+"\t");
			}
			System.out.println();
		}
我在使用这个语句时就会报错,报错信息为:

Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: {vector} [select a.usrName ,a.password from zuccess.zcplt.basic.privilege.model.User a where a.id not in (:data0_0_, :data0_1_) and (a.usrName not in :data20_0_, :data20_1_)]
	at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
	at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:284)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
	at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1254)
	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
	at zuccess.zcplt.basic.advanced.view.TestHQL.testTwo(TestHQL.java:62)
	at zuccess.zcplt.basic.advanced.view.TestHQL.main(TestHQL.java:35)



这是为什么?

举报
顶部