0 Replies Latest reply on Dec 26, 2012 6:01 AM by bardelman

    an org.hibernate.exception.ConstraintViolationException while persisting process instances

    bardelman

      Hi,

      i m developping a web application based on this example.

       

      In order to make my application storing already-started/unfinished processes/sessions and being able to retrieve them later(which is an avantage of the jbpm framework..); i want that these processes to be persisted on the database and not to be erased and replaced by a new data when a new record is persisted ,so , it is clear that the problem is about the property "hibernate.hbm2ddl.auto" on the persistance.xml's persistance-unit configuration..  but i actually have a problem to do this. My persistance.xml  looks like this :

       

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

      <persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd

      http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence">

       

           <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

              <jta-data-source>java:comp/env/jdbc/testDS1</jta-data-source>

              <class>org.drools.persistence.info.SessionInfo</class>

              <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

              <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>

              <class>org.drools.persistence.info.WorkItemInfo</class>

              <class>org.jbpm.process.audit.ProcessInstanceLog</class>

              <class>org.jbpm.process.audit.NodeInstanceLog</class>

              <class>org.jbpm.process.audit.VariableInstanceLog</class>      

       

       

              <class>org.jbpm.task.Task</class>

                               <class>org.jbpm.task.Comment</class>

                               <class>org.jbpm.task.Attachment</class>

                               <class>org.jbpm.task.I18NText</class>

                               <class>org.jbpm.task.SubTasksStrategy</class>

                               <class>org.jbpm.task.Deadline</class>

                               <class>org.jbpm.task.Escalation</class>

                               <class>org.jbpm.task.Reassignment</class>

                               <class>org.jbpm.task.Notification</class>

                               <class>org.jbpm.task.BooleanExpression</class>

                               <class>org.jbpm.task.User</class>

                               <class>org.jbpm.task.PeopleAssignments</class>

       

       

              <properties>

       

                   <!-- mysql dialect -->

       

                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

       

                  <property name="hibernate.connection.autocommit" value="false"/>

                  <property name="hibernate.max_fetch_depth" value="3"/>

                  <property name="hibernate.hbm2ddl.auto" value="update" />

                  <property name="hibernate.show_sql" value="false" />

                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup"/>

              </properties>

       

       

          </persistence-unit>

          <persistence-unit name="org.jbpm.task">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

       

              <class>org.jbpm.task.Attachment</class>

              <class>org.jbpm.task.Content</class>

              <class>org.jbpm.task.BooleanExpression</class>

              <class>org.jbpm.task.Comment</class>

              <class>org.jbpm.task.Deadline</class>

              <class>org.jbpm.task.Comment</class>

              <class>org.jbpm.task.Deadline</class>

              <class>org.jbpm.task.Delegation</class>

              <class>org.jbpm.task.Escalation</class>

              <class>org.jbpm.task.Group</class>

              <class>org.jbpm.task.I18NText</class>

              <class>org.jbpm.task.Notification</class>

              <class>org.jbpm.task.EmailNotification</class>

              <class>org.jbpm.task.EmailNotificationHeader</class>

              <class>org.jbpm.task.PeopleAssignments</class>

              <class>org.jbpm.task.Reassignment</class>

              <class>org.jbpm.task.Status</class>

              <class>org.jbpm.task.Task</class>

              <class>org.jbpm.task.TaskData</class>

              <class>org.jbpm.task.SubTasksStrategy</class>

              <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>

              <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>

       

              <class>org.jbpm.task.User</class>

       

              <class>org.drools.persistence.info.SessionInfo</class>

              <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

              <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>

              <class>org.drools.persistence.info.WorkItemInfo</class>   

       

              <properties>                                              

       

                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

                  <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm5webexpl" />

                  <property name="hibernate.connection.username" value="root"/>

                  <property name="hibernate.connection.password" value="sdfsdf"/>

       

       

                  <property name="hibernate.connection.autocommit" value="false" />

                  <property name="hibernate.max_fetch_depth" value="3"/>

                  <property name="hibernate.hbm2ddl.auto" value="update" />

                  <property name="hibernate.show_sql" value="false" />

              </properties>

          </persistence-unit>

      </persistence>

       

      while initiating a servlet which is responsible for the starting of the human-task service, users must be added :

      public class HumanTaskStartupServlet extends HttpServlet {

       

       

                 private static Log log = LogFactory.getLog(HumanTaskStartupServlet.class);

       

                 public void init() throws ServletException {

       

       

                        super.init();      

                                    try {

       

       

                                    EntityManagerFactory emfTask = Persistence.createEntityManagerFactory( "org.jbpm.task" );

                                    TaskService taskService = new TaskService(emfTask, SystemEventListenerFactory.getSystemEventListener());

       

       

       

                /*

                         * Add the required users

                         */

                        TaskServiceSession taskSession = taskService.createSession();  

       

                                taskSession.addUser(new User("Administrator"));

                                taskSession.addUser(new User("krisv"));

                                taskSession.addUser(new User("john"));

                                taskSession.addUser(new User("mary"));

       

       

                        /* Start Mina server for HT*/

                        MinaTaskServer server = new MinaTaskServer(taskService);

                        Thread thread = new Thread(server);

                        thread.start();

       

                        log.debug("Mina Server started ...");

                                    } catch (Throwable t) {

                                              log.error(t.getMessage(), t.getCause());

                                              throw new RuntimeException("can't start Mina server",t);

       

                                    }

       

                 }

       

       

      At the beginning, the property "hibernate.hbm2ddl.auto" on the persistence-unit named "org.jbpm.task"(the second one)  was set to "create" so always only one record remain on the database when i changed it to "update" i got this ERROR :

       

      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

                at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)

                at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

                at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)

                at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)

                at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)

                at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)

                at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)

                at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)

                at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)

                at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction(TaskServiceSession.java:716)

                at org.jbpm.task.service.TaskServiceSession.persistInTransaction(TaskServiceSession.java:682)

                at org.jbpm.task.service.TaskServiceSession.addUser(TaskServiceSession.java:69)

                at com.sample.taskserver.HumanTaskStartupServlet.init(HumanTaskStartupServlet.java:73)

                at javax.servlet.GenericServlet.init(GenericServlet.java:160)

                at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)

                at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)

                at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)

                at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)

                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)

                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)

                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)

                at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)

                at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

                at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

                at java.util.concurrent.FutureTask.run(Unknown Source)

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                at java.lang.Thread.run(Unknown Source)

      Caused by: java.sql.BatchUpdateException: Duplicate entry 'Administrator' for key 'PRIMARY'

                at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2020)

                at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)

                at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)

                at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

                ... 30 more

       

       

      and unfortunatelly it should be a fatal error as the application coudn't continue : i also got this ERROR:

       

      2012-12-26 01:45:33,559 (TaskProcessServlet.java:81) ERROR com.sample.processserver.TaskProcessServlet - Could not connect task client

       

      i need your help for this issue, CHEERS !