2 Replies Latest reply on Jul 9, 2012 7:45 AM by swiderski.maciej

    Cannot insert null  into table error while starting a process

    singhjess

      Hi all , we are using JBPM 5.3 on Jboss 7.1 with Hibernate 4 and using JBoss's transaciton manager  and seam managed persistence context, when I try to start  a  process I get the following error

       

       

       

      08:53:14,876 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) SQL Error: 23502, SQLState: 23502

      08:53:14,878 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-1) NULL not allowed for column "INSTANCEID"; SQL statement:

      insert into ProcessInstanceInfo (InstanceId, id, lastModificationDate, lastReadDate, processId, processInstanceByteArray, startDate, state, OPTLOCK) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [23502-161]

      08:53:14,888 ERROR [org.drools.persistence.SingleSessionCommandService] (http-localhost-127.0.0.1-8080-1) Could not commit session:

      : org.hibernate.exception.ConstraintViolationException

       

       

       

       

       

       

       

       

      public void

      startProcess() {

      try

      {

      KnowledgeBase kbase = readKnowledgeBase();

      TransactionManager manager = (TransactionManager) new InitialContext().lookup("java:jboss/TransactionManager"

      );

      // create the entity manager factory and register it in the environment

      EntityManagerFactory emf = Persistence.createEntityManagerFactory( "main"

      );

      Environment env = KnowledgeBaseFactory.newEnvironment();

      env.set( EnvironmentName.ENTITY_MANAGER_FACTORY

      , emf );

      //env.set( EnvironmentName.TRANSACTION, getUserTransaction());

      env.set(EnvironmentName.GLOBALS, new

      MapGlobalResolver());

       

      env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, entityManager

      );

      env.set(EnvironmentName.TRANSACTION_MANAGER

      , manager);

       

       

       

      Map<String, Object> params = new

      HashMap<String, Object>();

       

      // org.drools.persistence.info.WorkItemInfo wi;

      //org.jbpm.task.Comment comment;

       

      params.put("name", "Arthur"

      );

      params.put("money"

      , 1800);

       

       

      // create a new knowledge session that uses JPA to store the runtime state

      StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null

      , env );

      int

      sessionId = ksession.getId();

       

      System.out

      .println(sessionId);

      // invoke methods on your method here

      ksession.startProcess( "process_1"

      , params);

       

       

      ksession.dispose();

      } catch

      ( Throwable t ) {

      t.printStackTrace();

      }

       

       

      Here is my persistence.xml

       

       

       

       

      <

       

      persistence xmlns=

      "http://java.sun.com/xml/ns/persistence"

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • 1. Re: Cannot insert null  into table error while starting a process
          singhjess

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

          Sorry, the persitence.xml did not paste properly in the previous post

           

          <

           

          persistence xmlns=

          "http://java.sun.com/xml/ns/persistence"

           

          xmlns:xsi=

          "http://www.w3.org/2001/XMLSchema-instance"

           

          xsi:schemaLocation=

          "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

           

          version="2.0"

          >

           

          <persistence-unit name="main" transaction-type="JTA"

          >

           

          <description>Forge Persistence Unit</description

          >

           

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

          >

           

          <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source

          >

           

          <mapping-file>META-INF/JBPMOrm-JPA2.xml</mapping-file

          >

           

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

          >

           

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

          >

           

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

          >

           

          <exclude-unlisted-classes>false</exclude-unlisted-classes

          >

           

           

          <!--

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

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

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

          -->

           

          <properties

          >

           

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

          />

           

          <property name="hibernate.show_sql" value="true"

          />

           

          <property name="hibernate.format_sql" value="true"

          />

           

          <property name=

          "hibernate.transaction.flush_before_completion"

           

          value="true"

          />

           

          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"

          />

           

          </properties

          >

           

          </persistence-unit

          >

          </

           

          persistence

          >

          • 2. Re: Cannot insert null  into table error while starting a process
            swiderski.maciej

            one idea is that you need to update JBPMOrm-JPA2.xml to define sequence generator for InstanceId column as you run on Oracle...

             

            HTH