0 Replies Latest reply on Jan 7, 2006 1:19 PM by Martelli Julien

    How to configure Hibernate hilo key generation????

    Martelli Julien Newbie

      Hi, i am a newbie in j2ee and JBoss and i'm trying to deploy a ear file in JBoss 4.0.2 using Hibernate3 and MySQL 5.0.

      I am using a har file in my ear file for deployement and i am using the hilo generator to generate keys for my persistents objects. But i'm having trouble with this stuff because the hilo generator does'nt work. Here is the exception :

      19:08:49,005 ERROR [[action]] Servlet.service() for servlet action threw exception
      org.hibernate.TransactionException: JTA commit failed:
       at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:136)
       at coucheClient.ConfirmationSaisieVehiculeAction.execute(ConfirmationSaisieVehiculeAction.java:61)
       at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
       at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
       at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
       at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=reef-9jjshjf6ug/15, BranchQual=, localId=15] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:344)
       at org.jboss.tm.TxManager.commit(TxManager.java:200)
       at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:126)
       at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:130)
       ... 26 more
      Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
       at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:716)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:310)
       at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:58)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1384)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1076)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:296)
       ... 29 more
      Caused by: java.sql.BatchUpdateException: Duplicate entry '0' for key 1
       at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
       at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:701)
       at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
       ... 39 more
      


      And here is my hibernate config:
      <server>
       <mbean code="org.jboss.hibernate.jmx.Hibernate"
       name="jboss.har:service=BHibernate">
       <attribute name="DatasourceName">java:/autoWorkDS</attribute>
       <attribute name="Dialect">org.hibernate.dialect.MySQLDialect</attribute>
       <attribute name="SessionFactoryName">java:/hibernate/AutoWorkSessionFactory</attribute>
       <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
       <!-- <attribute name="Hbm2ddlAuto">create-drop</attribute> -->
       </mbean>
      </server>


      Here i smy datasource:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <datasources>
       <local-tx-datasource>
       <jndi-name>autoWorkDS</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/autoRent</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>****</password>
       </local-tx-datasource>
      </datasources>


      and here are my mapping file:
      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      <hibernate-mapping>
      <!--
       Auto-generated mapping file from
       the hibernate.org cfg2hbm engine
      -->
       <class name="coucheMapping.Tvehicule" table="tvehicule">
       <id name="vehId" type="long">
       <column name="veh_id" />
       <generator class="assigned" />
       </id>
       <property name="vehModele" type="string">
       <column name="veh_modele" length="15" not-null="true" />
       </property>
       <property name="vehMarque" type="string">
       <column name="veh_marque" length="15" not-null="true" />
       </property>
       <property name="vehCategorie" type="string">
       <column name="veh_categorie" length="15" not-null="true" />
       </property>
       <property name="vehAgence" type="string">
       <column name="veh_agence" length="15" not-null="true" />
       </property>
       <property name="vehImmatriculation" type="string">
       <column name="veh_immatriculation" length="15" not-null="true" />
       </property>
       <property name="vehCouleur" type="string">
       <column name="veh_couleur" length="15" not-null="true" />
       </property>
       </class>
      </hibernate-mapping>