0 Replies Latest reply on Jan 26, 2006 10:37 PM by Jens Elkner

    cannot commit with autocommit set ???

    Jens Elkner Apprentice

      Hmmm, since it seems to be impossible to persist and remove an entity within the same JTA, I 'm trying to manage the tx manually, i.e. with tx1 persist and within tx2 cleanup aka remove:


       EntityManagerFactory emf;
       EntityManager em;
       public void init() {
      // emf = Persistence.createEntityManagerFactory("foo");
       em = emf.createEntityManager();
       public void destroy() {
       if (em.isOpen()) {
      // if (emf.isOpen()) {
      // emf.close();
      // }
       public Catalog importCatalog(CatalogImportProfile profile,
       byte[] data, String clientId)
       Catalog catalog = null;
       try {
       mergeCatalog(profile, data);
       catalog = profile.getCatalog();
       em.getTransaction().commit(); // line 126 of CatalogImportSB
       } catch (Exception e) {
       return null;
       if (profile.isEnabled(Option.G_DELETE_EMPTY)) {
       try {
       } catch (Exception e) {
       return catalog;

      However, in this case I get:

      2006-01-27 03:22:45,874 ERROR [SocketServerInvokerThread-] - JDBC commit failed
      java.sql.SQLException: You cannot commit with autocommit set!
      at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:434)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)
      at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
      at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:36)
      at foo.CatalogImportSB.importCatalog(CatalogImportSB.java:126)

      1) The ds file for mySQL uses the "maxPerformance" config parameter, so there the "autocommit" is definitly set to false. So where the hell is the "autocommit" set?

      2) If I use emf.getEntityManager() in @PostConstruct, the #importCatalog always fails with "no transaction in progress". Reading the spec p.114 pfd I would assume, em.getTransaction().begin starts a new transaction and thus it should not fail. OK p.111 says, the ctx might be tx managed by the PersistenceProvider (in a SE! env) making #getEntityManager() completely wishywashy [useless aka unreliable?] (in this case #getTransaction() doesn't mak any sense to me).

      3) If I ommit the @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) on
      #importCatalog, the em.getTransaction().commit(); fails with:
      2006-01-27 04:02:29,073 ERROR [SocketServerInvokerThread-] - JDBC commit failed
      java.sql.SQLException: You cannot commit during a managed transaction!
      at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:432)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)

      Why? I actually want to end the tx and commit all changes, and since tx.commit() || tx.rollback() are the only ways to get a tx correctly finished ...
      Or does JBoss nest the #importCatalog automatically into another JTA? If so, why (I have not asked for that and - at least I assume - that 've created a tx before using any em method)?

      So the only workaround, that I've found for the "persist and remove bug" is to create a complete new em Factory and than a new em (i.e. not using an injected em factory).

      But I can't imagine, that this should be really the intended way for solving that issue. So, is someone able to comment on this,/ enlighten me, whether I got something wrong (or the spec is flawed, etc.)? Or is it simply, that JBoss 4.0.3SP1 does not follow the PFD yet?