7 Replies Latest reply on Nov 26, 2008 3:02 PM by salaboy21

    java.sql.SQLException: You cannot commit during a managed tr

    trouby

      Hey,

      I have created a very simple seam component that injects the jbpmContext and uses it to create the schema, this is the code:


      @name("workflowManager")
      public class WorkflowManager {
      
      @In
      private JbpmContext jbpmContext;
      
      
      public void createJbpmSchema() {
       jbpmContext.getJbpmConfiguration().createSchema()
      }
      }
      



      When invoked, I get the following exception:
      21:13:32,867 ERROR [SchemaExport] schema export unsuccessful
      java.sql.SQLException: You cannot commit during a managed transaction!
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:581)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:482)
       at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:30)
       at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
       at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
      ...
      



      I looked at the source code of the createSchema method,
      Seems like it's just invoking jbpmContext.close(); at the end.


      My JBPM/hibernate configured in the right way not to start/close a transaction it didn't start.



      What is the reason of the exception?


      Thanks,


      Asaf.

        • 1. Re: java.sql.SQLException: You cannot commit during a manage
          salaboy21

          No, you can not make a commit if you are under managed transactions, so you can not create an schema and commit it if you tell your container that handle the transactions for you.

          You must have your schema already generated when you use CMT.

          Hope it helps

          • 2. Re: java.sql.SQLException: You cannot commit during a manage
            trouby

            Hey,
            Thanks for the quick reply,

            I know that, but according to:
            7.1.3. Managed transactions in the manual, JBPM can be configured not to commit transactions at all when jbpmContext.close() is invoked.

            This is also described here:
            http://www.jboss.org/community/docs/DOC-11090


            So what causes JBPM to commit the transaction by itself and not leave it to the container?



            Thanks,

            Asaf.

            • 3. Re: java.sql.SQLException: You cannot commit during a manage
              salaboy21

              I think this is a special case.. because you need to commit in order to see the table that you have created...
              This section in the document, I supose that is for all the other situations.
              I must check the code to be sure...

              • 4. Re: java.sql.SQLException: You cannot commit during a manage
                trouby

                Hey,

                Not that I'm very familiar with JBPM's source code but here's the code of createSchema:

                public void createSchema(String jbpmContextName) {
                 JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
                 try {
                 Services services = jbpmContext.getServices();
                 DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
                 persistenceServiceFactory.createSchema();
                 } finally {
                 jbpmContext.close();
                 }
                 }
                



                I didn't see any JBPM code that commits the transaction, seems like persistenceServiceFactory.createSchema(); invokes the schema creation via Hibernate's SchemaExport class which probably somewhere perform the commit by itself,

                I didn't go to deep but if somone is familiar with it then I'll be glad for a solution,


                Otherwise, I'll try to invoke the method over a non-CMT,


                Thanks a lot :)


                Asaf.

                • 5. Re: java.sql.SQLException: You cannot commit during a manage
                  salaboy21

                  I'm also very familiar with this code, but also seem logical that the creation of the database needs to be persisted inmediately.
                  I don't think that is probable solution to call createSchema() inside CMT.

                  • 6. Re: java.sql.SQLException: You cannot commit during a manage
                    trouby

                    Yeah,
                    Probably because it involves of creating tables, so Hibernate commits it just after,


                    Well, I'll find another solution it's not a big deal, I just wanted to make sure that this is only for the schema related functionality and JBPM is not going to manage the transactions by itself when dealing with processes:-)





                    Thanks a lot, Salaboy! :-)

                    Asaf.

                    • 7. Re: java.sql.SQLException: You cannot commit during a manage
                      salaboy21

                      You're welcome, let us know if you have some troubles with another methods than createSchema() and dropSchema(), all the other method should work fine under CMT.