7 Replies Latest reply on Jan 7, 2013 6:04 AM by nickarls

    Readonly transactions in session beans

    lszymik

      I am looking for something similar to read-only transaction in spring for JBoss 7.1.x. Does JBoss 7 and JPA2 supports something like that? Where I could find more information for it or for general performance optimalization in JBoss 7.

       

       

      Thanks in advance.

        • 1. Re: Readonly transactions in session beans
          nickarls

          Are you talking about something like an EJB with a NOT_SUPPORTED transaction attribute? Or a non-transactional datasource?

          • 2. Re: Readonly transactions in session beans
            sfcoy

            JBoss does not explicitly support this notion. The fact is is that Spring Framework read-only transactions are poorly understood by developers that use it and it rarely does what you expect.

             

            See Transaction strategies: Understanding transaction pitfalls for more information.

            • 3. Re: Readonly transactions in session beans
              lszymik

              I was thinking about transaction within only read is allowed. Then data source and DB driver could make optimalization. Then only read is allowed and no data modification.

              • 4. Re: Readonly transactions in session beans
                nickarls

                If you're using Hibernate, I think it has the concept of Session.setDefaultReadOnly(true);

                • 5. Re: Readonly transactions in session beans
                  sfcoy

                  If you're concerned about performance then you're better off optimising your database queries and structure.   In addition, it's worthwhile minimising the number of transactions that are started/committed per user request/response. One is ideal, or two (for processing request, and then generating the response) although this is not always possible.  On some consulting jobs I've seen applications have mighty performance improvements simply by making use of correct Tx management. I've seen some applications create N+1 transactions per request/response and their performance was ugly.

                  • 6. Re: Readonly transactions in session beans
                    lszymik

                    I read article about transaction pitfalls. It is very interesting. So far I know that JPA2 does not support it directly and Hibernate Session could be used directly. I have real life scenarion where it is lot of I18N messages stored in database and there is stateless session bean which is providing method: getMessage(int id). The getMessage method is annotated with TransactionAttribute(REQUIRED) so read is executed inside transaction. The messages are rarely changed so I started to look for optimalizations. Springs developers told me to use transaction - read only. However now I am little bit confused. Maybe removing transaction from getMessage method will be better solution.

                     

                    Thanks for valueble information.

                    • 7. Re: Readonly transactions in session beans
                      nickarls

                      I think you get can get to the session from the EntityManager delegate.

                       

                      I have a similar case where I load my data into an @ApplicationScoped (@Singleton) bean, I then have a REST interface which I can call in order to flush the component and force a re-fetch if necessary.