2 Replies Latest reply on Jul 23, 2014 10:54 AM by vst77

    Native SQL Statements not handled by EJB transaction

    vst77

      Hi all,

       

      We are using Wildfly 8.1 and migrated our project from JBOSS 5. All works perfectly except the transaction handling of container managed EJBs.

       

      If we execute a native SQL statement, the changes will get persistent before the transaction is commited by the container.

      Thus the "delete from person" statement is never rolled back if an exception occurs. (The ApplicationException is annotated with rollback=true)

       


      @Stateless

      @LocalBean

      public class PersonSession

           public void recreatePersons() throws ApplicationException

           {

                manager.createNamedQuery("delete from person").executeUpdate();

       

                // all persons get deleted in the database even if the transaction is rolled back

                person1 = new Person();

                person1.setLastName("Smith");

               

                person2 = new Person();

                person2.setLastName("Johnson");

               

                manager.persist(person1);

                manager.persist(person2);

           }

      }