-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: hql problem(parameter binding with date)
PostPosted: Mon Dec 20, 2010 2:57 am 
Beginner
Beginner

Joined: Fri Nov 05, 2010 7:25 am
Posts: 21
Hi:
When I use HQL to do some date related query,I meet some problem which I can not find any answer after I read the HQL part of the hibernate manual and search from google,so I ask here for your guys's help.:)

Things are strange,it seems that the error result from the Query.setDate(xx,xx);

Main codes:

Code:
   //test 1
   @Test
   public void testUsingDateObject() {
      Session sess = factory.getCurrentSession();
      sess.beginTransaction();

      hql = "select en.name, count(en.name) from Entity en where en.time between ? and ? group by en.name";
      Query q = sess.createQuery(hql);
      q.setDate(0, start);
      q.setDate(1, end);
      List<?> list = q.list();
      printHibernateList(list);
   }

   //test 2
   @Test
   public void testUsingDateString() {
      Session sess = factory.getCurrentSession();
      sess.beginTransaction();

      // the start_str and end_str is built by new simpleDateFormat("yyyy-MM-dd HH:mm:ss").format(...)
      hql = "select en.name, count(en.name) from Entity en where en.time between '" + start_str + "' and '" + end_str + "' group by en.name";
      Query q = sess.createQuery(hql);
      List<?> list = q.list();
      printHibernateList(list);
   }
   
   private void printHibernateList(List<?> list) {
      for (Object obj : list) {
         if (list.size() < 1)
            System.out.println("no result");
         Object[] properties = (Object[]) obj;
         String name = properties[0].toString();
         long num = (Long) properties[1];
         System.out.println(name + ": " + num);
      }
   }


The test 2 works well,and I got the following error when I run test 1:

------------------------------
Code:
java.lang.reflect.UndeclaredThrowableException
   at $Proxy5.createQuery(Unknown Source)
   at com.test.TestHibernateQueryProjection.testUsingDateObject(TestHibernateQueryProjection.java:47)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
   ... 25 more
Caused by: java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
   at org.hibernate.hql.ast.HqlSqlWalker.generatePositionalParameter(HqlSqlWalker.java:921)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:5052)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1413)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4471)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4207)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
   ... 30 more



--------------------------------

The reason I say it is strange is that the same code worked well a few days ago,and I just integrate the struts2 in my application,is it the problem?


Top
 Profile  
 
 Post subject: Re: hql problem(parameter binding with date)
PostPosted: Wed Dec 22, 2010 4:11 pm 
Regular
Regular

Joined: Wed Feb 15, 2006 9:09 pm
Posts: 76
Quote:
Caused by: java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I

Hibernate uses ANTLR to parse HQL queries. It looks like some update you made changed the version of ANTLR that Hibernate sees in your classpath. Hibernate needs version 2.7.6, so double-check that there isn't a second antlr lying around in your classpath that's being picked up and is overriding the correct version.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.