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;
}
}