7 Replies Latest reply on Nov 18, 2009 5:11 AM by allanjun

    What's the default transaction attribute in EJB3.

    allanjun

      Do I have to always annotate session bean for transaction attribute?


      If I don't annotate my session bean with @TransactionAttribute, is there a default one like required, or no transaction will be applied?


      Thx.

        • 1. Re: What's the default transaction attribute in EJB3.
          v.lukoyanov

          If you don' annotate your bean, @TransactionAttribute(REQUIRED) will be applied.


          ----------

          My seam website

          • 2. Re: What's the default transaction attribute in EJB3.
            allanjun

            Thanks Vasilii.


            I also have a transaction propagation question.
            Say I have the following code.



            @Stateless
            public SBAImpl implements SBA {
            
             @EJB DaoA daoA;
             @EJB DaoB daoB;
            
             public void doSomething() {
                daoA.deleteRecord();
                daoB.createRecord();
             }
            }
            
            @Stateless
            public DaoAImpl implements DaoA {
              @PersistenceContext
              EntityManager em;
            
              public void deleteRecord() {
                // delete some records
                em.remove(......);
                em.flush();
              }
            }
            
            @Stateless
            public DaoBImpl implements DaoB {
              @PersistenceContext
              EntityManager em;
            
              public void createRecord() {
                // create some records
                em.persist(......);
                em.flush();
              }
            }
            
            



            As I understand, the transaction should be around the SBAImpl.doSomething() method, which means in the case of where DaoBImpl.createRecord() fails, transaction should be rollback. But what happened was record was still deleted from DaoAImpl.deleteRecord().


            What I got wrong here? Should the em be extended or the SB be stateful?


            Thx.


            • 3. Re: What's the default transaction attribute in EJB3.
              v.lukoyanov

              Hm, strange indeed. It should work as you expect. Although your problem could be related not to EJB/Hibernate, but to your DB Server. If you are using MySQL make sure you've chosen the right table model (e.g. innoDB).


              ----------

              My gallery

              • 4. Re: What's the default transaction attribute in EJB3.
                allanjun

                I'm using JBoss 5.1 with Oracle 10g.


                Is there a way to debug when transaction starts and ends?

                • 5. Re: What's the default transaction attribute in EJB3.
                  asookazian

                  In Seam apps, you should use @In rather than @EJB or @PersistenceContext, annotations from EE 5.


                  @In EntityManager em; uses Seam-managed persistence context rather than the EJB-container managed PC.


                  Read more in ref doc or SiA book.

                  • 6. Re: What's the default transaction attribute in EJB3.
                    kapitanpetko

                    Allan Li wrote on Nov 15, 2009 22:32:


                    I'm using JBoss 5.1 with Oracle 10g.

                    Is there a way to debug when transaction starts and ends?


                    There is. Unfortunately, it is neither straightforward, nor well documented. If someone knows an easier way, please advise.


                    The notes below are for JBoss 4.2, for 5.1 you should use the jbossts-properties.xml.


                    1. Add this to jboss-log4j.xml (you may want to add an appender, so this goes to a different file.)


                       <category name="com.arjuna.ats">
                          <priority value="TRACE" />
                       </category>
                    


                    2. Open conf/jbossjta-properties.xml and look for 'DebugLevel'. Change it to something like this: (more details here)


                    <property name="com.arjuna.common.util.logging.DebugLevel"
                              type="System" value="0x00000410"/>
                    


                    3. Restart JBoss.


                    4. Look for 'TransactionImple.commit' and the logs that follow it.


                    HTH


                    • 7. Re: What's the default transaction attribute in EJB3.
                      allanjun

                      Arbi Sookazian wrote on Nov 16, 2009 00:26:


                      In Seam apps, you should use @In rather than @EJB or @PersistenceContext, annotations from EE 5.

                      @In EntityManager em; uses Seam-managed persistence context rather than the EJB-container managed PC.

                      Read more in ref doc or SiA book.


                      Thanks for the reply Arbi.


                      But I have to use @EJB rather than @In as my ejbs are in a separate jar file.