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.  [ 1 post ] 
Author Message
 Post subject: createQuery problems
PostPosted: Thu Nov 08, 2007 5:37 am 
Newbie

Joined: Thu Nov 08, 2007 5:04 am
Posts: 1
Hi!
I'm getting this exception and can't locate what is wrong:

Code:
org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from com.test.model.User where userId = ?]
   org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:57)
   antlr.CharScanner.setTokenObjectClass(CharScanner.java:340)
   org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:31)
   antlr.CharScanner.<init>(CharScanner.java:51)
   antlr.CharScanner.<init>(CharScanner.java:60)
   org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
   org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
   org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
   org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:26)
   org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:44)
   org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:242)
   org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
   org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
   $Proxy4.createQuery(Unknown Source)
   com.test.model.UserManager.getUser(UserManager.java:15)
   com.test.test.DefaultController.handleRequest(DefaultController.java:21)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:858)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


My mapping file looks like this:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.redbet.model">
   <class name="User" table="users">

      <id name="userId" column="userId">
         <generator class="increment" />
      </id>

      <property name="username" column="username" />

   </class>
</hibernate-mapping>


And i have put the hibernate and antlr jar files in the lib directory, this is the code that fails, it fails on session.createQuery

Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

User result = (User) session.createQuery( "from User where userId = ?" ).setInteger( 0, userId ).uniqueResult();

session.getTransaction().commit();


The code for hibernateUtil looks like this:

Code:
static {
   try {
      InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream( "hibernate.cfg.xml" );

      Configuration configuration = new Configuration().addInputStream( in ).configure();

      sessionFactory = configuration.buildSessionFactory();
   } catch( Throwable ex ) {
      LOG.fatal( "Could not create session factory: " + ex.getMessage() );
      throw new ExceptionInInitializerError( ex );
   }
}

public static SessionFactory getSessionFactory() {
   return sessionFactory;
}


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

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.