0
votes

I am currently using just Hibernate and tomcat (no JBoss), and have hibernate transactions which I'm not clear on what transaction safety level I'm actually using, especially for those which read and get values and then update them). Thus I might be getting dirty reads?

So I'm going to start having to study my transactions that require non-dirty reads, and make sure that (1) hibernate controls the transaction safety level of those transactions properly, and (2) be able to still have those transactions where dirty reads are ok.

Do I need to install Hibernate with JBoss to control transaction safety levels? If so, what's the easiest way to do this without dramatically changing my application to use the J2EE apis, as I am currently using the basic Hibernate apis. Or better, can I get JTA control with Hibernate without using JBoss?

Andy

2

2 Answers

0
votes

Are you explicitly marking your transactions with em.getTransaction().begin() and commit()? If so, Hibernate will delegate the transaction management to the JDBC driver, and that you can configure with other properties (both at driver level and Hibernate level, like isolation levels).

If you then decide to use an Application Server, you can just set the property hibernate.transaction.factory_class to org.hibernate.transaction.JTATransactionFactory and Hibernate will join/create a transaction based on your instructions (em.getTransaction().begin() / commit()).

JTA is specially useful if you have two or more "transaction enabled" components, as JTA orchestrates the events and orders commits/rollbacks depending on the overall outcome. For instance, if you have one EJB transaction which persists something to the database and sends an email, both actions can be inside a transaction and it can be rolled back if any of them fails. But if you are interested only in database transactions, you don't really need JTA.

And to answer your last question: if you do need JTA but you don't want to use a EE Application Server, you can look for standalone JTA providers, like JOTM. But be careful: if you find yourself adding several "standalone" providers for different services, you may end up with a "home built EE server", which is not a good thing ;-)

0
votes

This are known as transaction isolation levels and below is the way to configure them in hibernate

hibernate.connection.isolation - Set the JDBC transaction isolation level. Check java.sql.Connection for meaningful values but note that most databases do not support all isolation levels. eg. 1, 2, 4, 8