3 Replies Latest reply on Mar 4, 2006 11:26 AM by pulsycouac

    Error storing objects with ejb3 entity

    pulsycouac

      Hello,

      I have trouble when trying to store objects with ejb3 entities. I follow the trailer (http://trailblazer.demo.jboss.com/EJB3Trail/) which is a very good support. However when I deploy my ear I have the following errors:

      FATAL [PersistenceXmlLoader] ejb3essaiPerst JTA

      and when I use the EntityManager to persist an object, an exception is throwned:

      00:09:25,872 WARN [JDBCExceptionReporter] SQL Error: -22, SQLState: S0002
      00:09:25,872 ERROR [JDBCExceptionReporter] Table not found in statement [insert into t_tech (prenom, nom) values (?, ?)]
      00:09:25,872 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.SQLGrammarException: could not insert: [fr.aulnette.essai.ejb3.entity.TechnicienBOBean]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      [...]

      Caused by: java.sql.SQLException: Table not found in statement [insert into t_tech (prenom, nom) values (?, ?)]
      at org.hsqldb.jdbc.Util.throwError(Unknown Source)
      [...]

      In fact the table creation doesn't appear anymore in the hsqldb log but I don't know why.

      The Entity bean code:
      -------------------------

      @Entity
      @Table(name="t_tech")
      public class TechnicienBOBean implements Serializable {

      String nom;
      String prenom;
      //SiteBOBean site;

      @Id
      public String getNom() {
      return nom;
      }

      public void setNom(String nom) {
      this.nom = nom;
      }
      [...]
      }


      The Session Stateless bean code:
      ---------------------------------------

      @Stateless
      public class TechnicienBSBean implements TechnicienBSI, TechnicienRemoteBSI {
      @PersistenceContext(unitName="ejb3essaiPerst")
      protected EntityManager em;

      public void storeTechnicienInDB(String nom, String prenom) {
      TechnicienBOBean technicienEntity = new TechnicienBOBean();
      technicienEntity.setNom(nom);
      technicienEntity.setPrenom(prenom);
      em.persist(technicienEntity);
      }
      [...]
      }


      The persistence.xml file is embedded into the META-INF directory of my ejb findTechnicien-ejb.jar:
      -------------------


      <persistence-unit name="ejb3essaiPerst">
      <jta-data-source>java:/DefaultDS</jta-data-source>
      </persistence-unit>


      The application.xml file is embedded into the META-INF directory of my ear:
      -------------------


      <display-name>findTechnicien</display-name>

      findTechnicien-ejb.jar



      Some help would be very appreciated because i have no more ideas.

      thank you,

      --
      Jeremy Goldschmidt
      France

        • 1. Re: Error storing objects with ejb3 entity
          pulsycouac

          I tried the following:

          - I had this to the persistence.xml

          <properties>
           <property name="hibernate.hbm2ddl.auto"
           value="create-drop"/>
           </properties>


          The trace into hsqldb log file is:
          SET AUTOCOMMIT TRUE
          drop table t_tech if exists
          create table t_tech (nom varchar(255) not null, prenom varchar(255), primary key (nom))
          SET AUTOCOMMIT FALSE
          INSERT INTO T_TECH VALUES('NomTech1','PrenomTech1')
          COMMIT


          The error thrown become and i always have the FATAL error on [PersistenceXmlLoader] when deploying my ear

          08:47:17,858 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
          08:47:17,858 ERROR [JDBCExceptionReporter] failed batch
          08:47:17,858 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
          org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
          [...]

          • 2. Re: Error storing objects with ejb3 entity

             

            "pulsycouac" wrote:

            However when I deploy my ear I have the following errors:

            FATAL [PersistenceXmlLoader] ejb3essaiPerst JTA


            You can ignore this one, http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3920642#3920642

            • 3. Re: Error storing objects with ejb3 entity
              pulsycouac

              You're right,

              In fact the problem was in an other place, my persistence action works well but i did it two times without catching the exception thrown during the second insert.

              I was focus on this fatal error, that's why I was blind about other reason of my error.

              Everything works well now, thank you for your reply.

              --
              Jeremy Goldschmidt