Announcement Announcement Module
Collapse
No announcement yet.
getHibernateTemplate.find() problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • getHibernateTemplate.find() problem

    I'm working with Hibernate2.1.6, Tomcat 5.0.28 and Spring 1.1.1. My OS is a woody debian.

    In my class HibernateToto (extends HibernateDaoSupport) I'm doing the following request:

    getHibernateTemplate().save(objToto);
    This is always working to put data in the TOTO table.

    but to get data from the table, I have some difficulties:
    obj = getHibernateTemplate().find("from i in class TOTO where i.code=?",
    "ABC", Hibernate.STRING);

    This is working in the case of test, i.e with a Spring Context Bean (ClassPathXmlApplicationContext). So, In this case, Tomcat is not launched.

    When I running my web aplication, I have no database error. With p6spy I can check that the SQL request is sent. But I have no return and there is no SQL error. I have only the following message from Tomcat:

    java.lang.ClassCastException at org.apache.jsp.WEB_002dINF.views.jsp.error.uncaugh tException_jsp._jspService(uncaughtException_jsp.j ava:80) at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94) at javax.servlet.http.HttpServlet.service(HttpServlet .java:802) at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324) at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292) at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236) at javax.servlet.http.HttpServlet.service(HttpServlet .java:802) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157) at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:704) at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:476) at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:409) at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:312) at org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:91) at org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:241) at org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:678) at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:562) at org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:321) at javax.servlet.http.HttpServlet.service(HttpServlet .java:802) at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157) at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:704) at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:476) at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:409) at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:312) at org.apache.catalina.core.StandardHostValve.custom( StandardHostValve.java:396) at org.apache.catalina.core.StandardHostValve.throwab le(StandardHostValve.java:225) at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:145) at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534)
    ----------------------------------
    But what is strange is that when I'm doing the request property by property, it is working: for example,

    List list = getHibernateTemplate().find("select i.TOTO_id from i in class TOTO where i.code=?", "ABC", Hibernate.STRING);

    I tried whith another version of Tomcat (Tomcat 4.1.31) or Spring (Spring 1.0) without any succes. Is there something special more to configure between Tomcat and Spring/Hibernate (The configuration I have was working with Spring 1RC2, Hibernate 2.0, and Tomcat 4). I would like to add that I'm deleting the working directory of Tomcat to be sure that my configuration before each attempt.

    Could someone give me a clue ?
    :P :P

  • #2
    Could you try to make your query : "from TOTO i where i.code=?" ?
    And is TOTO a subclass of a persistent class or a superclass ?

    Olivier

    Comment


    • #3
      The HQL request is translated this way:
      select i.TOTO_id as x0_0_, i.code as x1_0_, i.name as x2_0_, i.titi as x3_0_, i.tutu as x4_0_ from TOTO i where (i.code='ABC');

      Under sql, it is working fine: that's why there is no JDBC error I think. The problem is just after the request has been done.

      The code is the following:
      public class HibernateTOTO extends HibernateDaoSupport implements TOTOImpl {
      public maclasse.TOTO getTOTO(String stgTOTO) throws DataAccessException {
      Object obj = null;
      try {
      List list = getHibernateTemplate().find("select i.TOTO_id,i.code,i.name,i.titi,i.ttu from i in class TOTO where i.code=?",stgTOTO, Hibernate.STRING);
      //OK
      log.info("#1"+list.get(0));
      // NOK
      obj = getHibernateTemplate().find("from i in class TOTO where i.code=?",
      stgTOTO, Hibernate.STRING);
      // THERE IS A PB HERE -> the exception is sent here directly to tomcat
      // NEVER EXECUTED
      log.info("#2"+obj);
      obj = getHibernateTemplate().find("from i in class TOTO where i.code=?",
      stgTOTO, Hibernate.STRING).get(0);
      log.info("#3"+obj);
      return (obj == null ? null : (maclasse.TOTO)obj);

      // empty table
      // NEVER EXECUTED
      } catch (java.lang.IndexOutOfBoundsException e) {
      log.info("getTOTO()::IndexOutofBoundsException");
      return null;
      }
      // NEVER EXECUTED
      catch (java.lang.Exception e) {
      log.info("#error#" +e.getMessage());
      return null;
      }
      }

      The class TOTO is a main class with a many-to-many relationship with table TOTO2. But I've declared the table TOTO_TOTO2 with the property lazy, so this is not involved in the query (as we can see in the request where there are just the fields of TOTO).

      I'v just changed the place where the query is launched in my program and now, I have something more explicit (not really for me):

      0 nov. 2004 22:22:00 maclasse.persistence.HibernateTOTO getTOTO
      INFO: #1[Ljava.lang.Object;@10fb9bd
      10 nov. 2004 22:22:00 org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController getExceptionHandler
      INFO: Trying to find handler for exception class [java.lang.NoClassDefFoundError]
      10 nov. 2004 22:22:00 org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController getExceptionHandler
      INFO: Trying to find handler for exception superclass [java.lang.NoClassDefFoundError]
      10 nov. 2004 22:22:00 org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController getExceptionHandler
      INFO: Trying to find handler for exception superclass [java.lang.LinkageError]
      10 nov. 2004 22:22:00 org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController getExceptionHandler
      INFO: Trying to find handler for exception superclass [java.lang.Error]
      10 nov. 2004 22:22:00 org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
      INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [modelView,errorHttpView,loginErrorView,topBannerRe gisteredView,totoView,rightPanelView,insertForm,to pBannerView,welcomeView,dataAccessFailure,topBanne rSignonView,welcomeMiddleSubView,dataConsultView,i nsertRedirect,signonForm,subgraphicView,graphicVie w,dataImportView]; parent=<org.springframework.web.context.support.Xm lWebApplicationContext: displayName=[XmlWebApplicationContext for namespace 'TOTO-servlet']; startup date=[Wed Nov 10 22:21:23 CET 2004]; parent=[org.springframework.web.context.support.XmlWebAppl icationContext: displayName=[Root XmlWebApplicationContext]; startup date=[Wed Nov 10 22:21:15 CET 2004]; root of ApplicationContext hierarchy; config locations=[/WEB-INF/applicationContext-hibernate.xml]; ]; config locations=[/WEB-INF/TOTO-servlet.xml]; >]
      10 nov. 2004 22:22:00 org.springframework.beans.factory.support.Abstract BeanFactory getBean :twisted: :!:

      Comment


      • #4
        Could you try
        Code:
         obj = getHibernateTemplate&#40;&#41;.find&#40;"from TOTO i where i.code=?", stgTOTO, Hibernate.STRING&#41;;
        instead of
        Code:
         obj = getHibernateTemplate&#40;&#41;.find&#40;"from i in class TOTO where i.code=?", stgTOTO, Hibernate.STRING&#41;;
        ? I saw no mention of the "in class xxx" expression in the HQL manual (except in the sample section ...) and I'm not sure it is useful there.

        Also, there's a "ttu" expression in the first HQL while the jdbc attribute seems to be "tutu". Is it ok or just a bad copy/paste ?

        Olivier

        Comment


        • #5
          Thanks for your response.
          I've tried the syntax but it is not worling (in fact I've tried the second syntax since the first was not working).
          For ttu, yes it's a bad syntax.
          Anyway, I've check that the mysql driver is in the jre/lib/ext directory and that the right library are in the WEB-INF/lib directiory.

          Christophe

          Comment


          • #6
            Some jakarta-commons were missing in my WEB-INF/lib. Now it is working.

            It should be notice that there is no error message when the called is performed from a SimpleFormController. When a call is performed from a MultiActionController, Tomcat tells me what kind of error it is.

            Christophe

            Comment

            Working...
            X