1 Reply Latest reply on Sep 21, 2010 3:15 AM by xmedeko

    Session bean method - read-only transaction

    xmedeko

      Hi,

       

      is there any way, how to mark a method in @Stateless session bean as "read-only" in regards to the database transaction?

       

      I mean something like Spring has: it should make a "read-only" DB transaction (if JDBC driver supports that) and set the Hibernate FlushMode to NEVER. It should improve the performance, because the Hibernate would not flush the session. The Hibernate shoudl save some time, by not walking through all managed entities and checking, if something has been modified, eg. see this link.

       

      I have tried to mark my method as

       

      {code}@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED){code}

       

      But my check

       

      {code}System.out.println("flush mode: " + HibernateHelper.getSession(this.em).getFlushMode());{code}
      

       

      prints "AUTO". Furthemore, I cannot initialize LAZY realtionships when the TransactionAttribute is set to NOT_SUPPORTED.

       

      Thanks

      Andy

        • 1. Re: Session bean method - read-only transaction
          xmedeko

          Well, after a day of search and discussion with some people, I guess JPA 1.0 does not allow this directly. The  TransactionAttributeType.NOT_SUPPORTED is not what I need. So, I just set direcly

          HibernateHelper.getSession(this.em).setFlushMode(FlushMode.MANUAL)

          and that's it.