-
1. Re: Readonly transactions in session beans
nickarls Jan 4, 2013 8:34 AM (in response to lszymik)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 Jan 7, 2013 12:57 AM (in response to lszymik)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 Jan 7, 2013 4:57 AM (in response to nickarls)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 Jan 7, 2013 5:01 AM (in response to lszymik)If you're using Hibernate, I think it has the concept of Session.setDefaultReadOnly(true);
-
5. Re: Readonly transactions in session beans
sfcoy Jan 7, 2013 5:19 AM (in response to lszymik)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 Jan 7, 2013 5:30 AM (in response to sfcoy)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 Jan 7, 2013 6:04 AM (in response to lszymik)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.