-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help -- Problem with createQuery()
PostPosted: Thu Jul 06, 2006 3:38 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
I am using Hibernate 3.1.3. I am new to Hibernate. I have read the documentation on Hibernate's website.

I am creating a Delete Query and getting this error when I invoke session.createQuery(...) from my Web Application. I don't get this error when I run my code from a static main method.

org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [DELETE mil.army.ds.amed.pac.mn.pftresubmit.hibernate.Export WHERE fmp=:fmp AND exercise=:edate]
at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:57)
at antlr.CharScanner.setTokenObjectClass(CharScanner.java:340)
at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:31)
at antlr.CharScanner.<init>(CharScanner.java:51)
at antlr.CharScanner.<init>(CharScanner.java:60)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:26)
at org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:44)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:232)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at mil.army.ds.amed.pac.mn.pftresubmit.dataoperations.DataExport.removeRecord(DataExport.java:42)
at mil.army.ds.amed.pac.mn.pftresubmit.pagebeans.BeanPFTResubmit.remove(BeanPFTResubmit.java:54)
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:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)


Code:
package mil.army.ds.amed.pac.mn.pftresubmit.dataoperations;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import mil.army.ds.amed.pac.mn.pftresubmit.hibernate.MedExamsSession;
import mil.army.ds.amed.pac.mn.util.Util;

public class DataExport {
   
  private Session session;
  private static String DELETE =
    "DELETE Export WHERE fmp=:fmp AND exercise=:edate";

  public DataExport() {
      
    super();      
  }
   
  public void beginSession(boolean debug_in) {
   
    MedExamsSession medexamssession = new MedExamsSession();
    medexamssession.setDebug(debug_in);
    this.session = medexamssession.getSessionFactory().openSession();
  }
   
  public void endSession() {
    try {
      this.session.close();
    } catch (Exception e) {
    }
  }
   
  public void removeRecord(String fmp_in, String date_in) throws
    Exception {
      
    Transaction tx = this.session.beginTransaction();
    try {
>>  Query deletequery = this.session.createQuery(DELETE); <<Error here
      deletequery.setString("fmp", fmp_in);
      deletequery.setTimestamp("edate", Util.StringDate(date_in));
      deletequery.executeUpdate();      
    } catch (Exception e) {
      tx.rollback();
      throw e;
    }   
    tx.commit();
  }   
}



The above code works when I call it from a static main method:

Code:
package mil.army.ds.amed.pac.mn.pftresubmit;

import mil.army.ds.amed.pac.mn.pftresubmit.dataoperations.DataExport;

public class Test {

  public Test() {
    super();
  }

  public static void main(String[] args) throws Exception {

    DataExport export = new DataExport();
    export.beginSession(true);
    export.removeRecord("01112560550", "2002-May-02");
    export.endSession();
  }
}


It doesn't work when I call it from my bean:

Code:
package mil.army.ds.amed.pac.mn.pftresubmit.pagebeans;

import mil.army.ds.amed.pac.mn.pftresubmit.Globals;
import mil.army.ds.amed.pac.mn.pftresubmit.dataoperations.DataExport;
import mil.army.ds.amed.pac.mn.pftresubmit.utilities.ParseText;

public class BeanPFTResubmit {

  private String inputtext = "";
  private String outputstatus = "";
 
  public BeanPFTResubmit() {
  }

/*
* Get, Set Properties
*/

  public void setInputText(String inputtext) {
    this.inputtext = inputtext;
  }
  public String getInputText() {
    return this.inputtext;
  }

  public String getOutputStatus() {
    return this.outputstatus;
  }

/*
* Remove "bad" PFT exams from exported list.
*/

  public String remove() {
 
    DataExport dataexport = new DataExport();
    dataexport.beginSession(Globals.DEBUG);
    ParseText parsetext = new ParseText(this.inputtext);
    this.outputstatus = "";
   
    while (parsetext.find()) {
      try {
        dataexport.removeRecord(parsetext.getFmp(),
          parsetext.getExamDate());
        this.outputstatus += "Removed: " + parsetext.getFmp() + " -- "
          + parsetext.getName() + " -- " + parsetext.getExamDate()
          + "<BR>";

      } catch (Exception e) {
        this.outputstatus += "Error: " + parsetext.getFmp() + " -- "
          + parsetext.getName() + " -- " + parsetext.getExamDate()
          + "<BR>";
        this.outputstatus += e.getMessage() + "<BR>";
        e.printStackTrace();
      }       
    }
    dataexport.endSession();
    return null;
  }

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 11:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Looks like a bad or missing jar file. Though I don't know how, seeing as the method that's throwing the Exception is in the same package as the class that can't be found. Anyway, check that hibernate3.jar is in all required classpaths. It'll be needed by both the web app (which already has it) and whatever app executes the line that's failing.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 12:32 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
It's not a missing jar file. hibernate3.jar is in the class path -- otherwise I wouldn't be able to create a session or transaction at all.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 09, 2006 5:55 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's why I said "but I don't know how". Are there two apps in use here, one webapp and a separate business logic/data access layer app? Is it possible that you're turned off the AST parser on the server side? Obviously the webapp has the right jar, but maybe something else doesn't, or is configured differently.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 12:43 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
What is the AST Parser? How is it turned on and off?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:46 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
I believe the AST parser is the technology used to parse HQL which you are using and its part of Hibernate. Maybe you can try the following command and confirm you get the same output, maybe your hibernate3.jar is corrupted ?

Code:
$ jar -tvf /opt/hibernate-3.1.3/hibernate3.jar  | grep HqlToken
  3938 Mon Mar 20 14:15:28 GMT 2006 org/hibernate/hql/antlr/HqlTokenTypes.class
  1294 Mon Mar 20 14:15:30 GMT 2006 org/hibernate/hql/ast/HqlToken.class


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:57 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
I have both classes in my Hibernate3.jar.

Everything is OK when I run my static test program. I'm only getting an error when I run my Web application.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 3:06 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
nakamuram wrote:
I have both classes in my Hibernate3.jar.

Everything is OK when I run my static test program. I'm only getting an error when I run my Web application.


Okay, I presume you fully understand the classpath differences between a static test program and a web-application running under a container ?

Have you only the one copy of the hibernate*.jar on your computers, or have you a copy in your WEB-INF/lib and have you also provided the necessary supplementary JARs in WEB-INF/lib ?

So ignoring a JVM level ClassNotFound error, which the above relates to.


Lets presume its a ClassNotFound from a class being referenced inside you HQL. Is the class mil.army.ds.amed.pac.mn.pftresubmit.hibernate.Export also available in the WEB-INF/lib or WEB-INF/classes tree ?

Given the fact it has the HqlToken and a verbose snipped of HQL in the exception comment information of the ClassNotFound I don't think this is a JVM generated exception anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 6:10 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
This problem is definitely not a Class Path Problem. I made sure that the paths were correct before I asked for help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 6:49 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The parser you use to interpret HQL is specified in your .cfg.xml file, using the hibernate.query.factory_class property. It should either be absent or set to org.hibernate.hql.ast.ASTQueryTranslatorFactory.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 2:14 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
No. Setting the "hibernate.hibernate.query.factory_class" to "org.hibernate.hql.ast.ASTQueryTranslatorFactory" did not work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 2:25 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
However, setting it to "org.hibernate.hql.classic.ClassicQueryTranslatorFactory" yields the error message: "query must begin with SELECT or FROM:..." In the Web-Application and the Test Application.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 4:49 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
are you running in weblogic?

http://www.hibernate.org/250.html#A25

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 6:17 pm 
Newbie

Joined: Thu Jul 06, 2006 3:07 pm
Posts: 9
I am running Oracle Application Server (JDeveloper 10.1.3) and JBOSS 4.0.4.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 11:34 am 
Newbie

Joined: Wed Jul 19, 2006 12:50 pm
Posts: 2
Hi,

I also encountered the same exception, with JDev 10.1.3.
Try replacing the antlr.jar in <jdev directory>\toplink\lib with the one found in hibernate3; it worked for me. (i found out about this solution here: http://www.it-eye.nl/weblog/2006/02/02/ ... bernate-3/)


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

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.