0 Replies Latest reply on Aug 18, 2008 1:12 PM by vanyatka

    DDL statement inside a transaction (mysql)

    vanyatka

      Hi,

      There is a transactional SLSB method that uses EntityManager.
      It does some business logic, and on its finish all DB changes should be made persistent or rolled back.

      The problem is that along the way some DDL statements must also be executed. And MySQL cannot execute those statements inside the same SQL transaction, forcing to commit all outstanding changes.
      http://dev.mysql.com/doc/refman/5.0/en/implicit-commit.html

      I tried to workaround the problem, issuing DLL statements inside a new transaction, like this:

      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
       public int ddl(String ddl) {
       log.warn("DDL is #0", ddl);
       return entityManager.createNativeQuery(ddl).executeUpdate();
       }
      


      But in spite of REQUIRES_NEW attribute all previous changes of *parent* transaction are also made persistent.

      Can you suggest what might be the problem?

      Thanks,