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

    cannot commit with autocommit set ???

    elkner

      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:

      SLSB

      ...
       @PersistenceUnit(unitName="foo")
       EntityManagerFactory emf;
       EntityManager em;
      
       @PostConstruct
       public void init() {
      // emf = Persistence.createEntityManagerFactory("foo");
       em = emf.createEntityManager();
       }
      
       @PreDestroy
       public void destroy() {
       if (em.isOpen()) {
       em.close();
       }
      // if (emf.isOpen()) {
      // emf.close();
      // }
       }
      ...
       @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
       public Catalog importCatalog(CatalogImportProfile profile,
       byte[] data, String clientId)
       {
       Catalog catalog = null;
       em.getTransaction().begin();
       try {
       mergeCatalog(profile, data);
       catalog = profile.getCatalog();
       em.getTransaction().commit(); // line 126 of CatalogImportSB
       } catch (Exception e) {
       log.warn(e.getLocalizedMessage());
       em.getTransaction().rollback();
       return null;
       }
       if (profile.isEnabled(Option.G_DELETE_EMPTY)) {
       em.getTransaction().begin();
       try {
       removeEmptyGroups(profile.getCatalog().getId());
       em.getTransaction().commit();
       } catch (Exception e) {
       log.warn(e.getLocalizedMessage());
       em.getTransaction().rollback();
       }
       }
       return catalog;
       }
      


      However, in this case I get:

      2006-01-27 03:22:45,874 ERROR [SocketServerInvokerThread-192.168.21.1-350:org.hibernate.transaction.JDBCTransaction:124] - 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-192.168.21.1-351:org.hibernate.transaction.JDBCTransaction:124] - 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?