12 Replies Latest reply on Nov 19, 2012 9:01 AM by rafaelps.java

    Transaction propagation doesn't work

    bogoliy

      Hello!

      I have some troubles with transactions on JBOSS AS 7.  When I call from my EmployerDAO some methods of other EJBs it usually results in deadlock on DB2 database.

      I can't understand the reason, as all logic should be executed in one transaction - but unfortunatly deadlocks appears.

      I have attached my persistence xml.


      my datasource configuration in JBOSS:

       

       <xa-datasource jndi-name="java:/jdbc/BS" pool-name="BS" enabled="true" use-java-context="true" use-ccm="true">
                          <xa-datasource-property name="DatabaseName">
                              DEMO45N2
                          </xa-datasource-property>
                          <xa-datasource-property name="ServerName">
                              192.168.32.40
                          </xa-datasource-property>
                          <xa-datasource-property name="PortNumber">
                              50001
                          </xa-datasource-property>
                          <xa-datasource-property name="DriverType">
                              4
                          </xa-datasource-property>
                          <xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
                          <driver>org.db2</driver>
                          <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                          <xa-pool>
                              <max-pool-size>8</max-pool-size>
                              <prefill>false</prefill>
                              <use-strict-min>false</use-strict-min>
                              <flush-strategy>FailingConnectionOnly</flush-strategy>
                              <pad-xid>false</pad-xid>
                              <wrap-xa-resource>false</wrap-xa-resource>
                          </xa-pool>
                          <security>
                              <user-name>db2inst1</user-name>
                              <password>asdf</password>
                          </security>
                          <validation>
                              <validate-on-match>false</validate-on-match>
                              <background-validation>false</background-validation>
                              <background-validation-millis>1</background-validation-millis>
                              <use-fast-fail>false</use-fast-fail>
                          </validation>
                          <statement>
                              <prepared-statement-cache-size>0</prepared-statement-cache-size>
                          </statement>
                      </xa-datasource>
      
      

       

      My code :

       

      
      @Stateless(name = "employerDAO")
      @Local(value = EmployerDAO.class)
      public class EmployerDAOImpl extends BaseDAOImpl<Employer> implements EmployerDAO {
      
      @EJB
      private EmployeeDAO employeeDAO;
      @EJB
      private SubgroupDAO subgroupDAO;
      
      
      .....
      @Override
      public void changeStatus(long employerId, OrganizationStatus status,EmployeeStatus employeeStatus, String reason) {
      subgroupDAO.changeStatusOfOrganizationSubgroups(status, employerId);
      employeeDAO.changeStatusOfOrganizationEmployees(employeeStatus, employerId);
      Employer employer = getEntityManager().find(Employer.class, employerId);
      employer.setStatus(status);
      employer.setStatusReason(reason);
      employer.setStatusDate(new Date());
      }
      
      ....
      }
      
      

      Is that is bug ? Thanks for response.

        • 1. Re: Transaction propagation doesn't work
          sfcoy

          Hi there, welcome to the JBoss Forums!

           

          You are experiencing a generic issue with DB2. We have seen this problem on both WebSphere 7 and JBoss EAP 5.x.

           

          In general we have been able to resolve it by experimenting with transaction isolation levels. Not ideal I know. We've also seen this on MS SQL Server. These databases have this tendency to dynamically escalate lock levels which makes their behaviour difficult to predict.

          1 of 1 people found this helpful
          • 2. Re: Transaction propagation doesn't work
            wdfink

            I don't see a problem there. How does the Employer class looks like.

            How do you detect the deadlock?

            Do you have concurrent access in the application or database?

            Maybe logging of JPA/Hibernate/Transaction at DEBUG/TRACE will help.

            • 3. Re: Transaction propagation doesn't work
              bogoliy

              There is no concurrent access in the application to database.

              Logs were not helpfull.

              Deadlock I have detected through DB2 Control Center.

              On prostgre everything is ok.

              • 4. Re: Transaction propagation doesn't work
                bogoliy

                In general we have been able to resolve it by experimenting with transaction isolation levels.

                Can you , please, explain how you have fixed the problem using isolation levels?

                • 5. Re: Transaction propagation doesn't work
                  sfcoy

                  Look in your datasource definition:

                   

                  {code:xml}<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>{code}

                   

                  Try TRANSACTION_READ_UNCOMMITTED or TRANSACTION_REPEATABLE_READ.

                  • 6. Re: Transaction propagation doesn't work
                    smarlow

                    I agree about trace logging, you need to see what is actually going on.  Try enabling TRACE logging for arjuna + orb.jboss.as.jpa as mentioned here. 

                     

                    That will show for each thread:

                     

                    • The EntityManager operation
                    • The start/end of each JTA transaction

                     

                    Also, you said that your using AS 7, you should upgrade to 7.1.1 (if you haven't yet).  You should always try the latest community version.

                     

                    Regarding your question about possible bugs.  When you hit a database deadlock, you should examine the details (identify which database rows are involved) of the deadlock.  Its not rocket science, just time consuming (especially if you have to fight with the database tools to get the details).

                     

                    Looking at the time that the deadlock occurred, you can look at the AS7 TRACE logging activity that led to the deadlock.  Once you have the details of what went wrong in the database and how your application code caused it, you can work towards a solution.

                     

                    Scott

                    • 7. Re: Transaction propagation doesn't work
                      bogoliy

                      I have already enabled tracing. But I see just one transaction starting.

                      Yes I have examine details of lock. But as I understand it doesn't metter what is locked - the question is why it is locked if there is should be just one trasnaction...

                      • 8. Re: Transaction propagation doesn't work
                        smarlow

                        Alex,

                         

                        Your server.log only shows one transaction and that transaction doesn't complete because of the deadlock?  In english, what are the details of the deadlock?  Show us the "deadlock" error message also.

                         

                        About how many users are using the application when it hits the deadlock?  From your description, it sounds like your saying only one user is using the application, which sounds strange.

                         

                        Generally, a deadlock will occur when two different database connections, obtains two database locks in reverse order (e.g. connection one locks PK=1 and waits for lock on PK=2, connection two locks PK=2 and waits for lock on PK=1).

                         

                        Scott

                        • 9. Re: Transaction propagation doesn't work
                          bogoliy

                          When I set on business method changeStatus transaction attibute - NOT_SUPPORTED, and on DAO method REQUIRED - No locks.

                          When remove NOT_SUPPORTED  - it locks.

                          So I think it is some bug with transaction join on jboss and db2.

                          • 10. Re: Transaction propagation doesn't work
                            rafaelps.java

                            I solve this problem of the transaction propragation doesn't work in Jboss 7 with this:

                            In the interfaces don't use inheritences to declare a method that the EJB must implements.

                             

                             

                            Not good but, i can continue using jboss 7 until, jboss developers solve this problem.

                            Please anyone try do what i said and relate this bug.

                             

                            This is a Bug that Jboss 7 has.

                             

                            In others versions of jboss i didn't have this problem.

                             

                             

                            { SCJP 6, SCWCD 5, OCPBCD 5 }

                            • 11. Re: Transaction propagation doesn't work
                              jaikiran

                              Rafael, welcome to the forums!

                               

                              Can you please post an example? The one in the first post of this thread doesn't have much details about the class hierarchy.

                              • 12. Re: Transaction propagation doesn't work
                                rafaelps.java

                                jaikiran pai all basics steps that i did in example of code full enough to understand the way work, and don't