I'm using hibernate 3.6 with MSSQL 2005, 2008, 2012.
I would like to set the isolation level of a transaction created by the session, but I can't find any information about in.
This is my code
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
throw e; // or display error message
}
finally {
sess.close();
}
I would like an to do something like that
sess.beginTransaction(1|2|4|8);
Is that possible?
Thank you.
Isolation in hibernate is similar to transactional isolations provided by database i. e the degree to which the data being updated is visible to other transaction taking place concurrently. Every database provide default isolation settings. There are isolation-levels. And hibernate provides you to set the isolation level for your application.
Fluent NHibernate doesn't do anything with the transaction isolation, so the default will be whatever NHibernate defaults to. I don't know off the top of my head what that is.
Because of repeatable reads isolation level, Hibernate's sees exactly the same number of rows for every SELECT query under began transaction. This level acts like a cache, so we can tell that the reads are faster than usually. But in the other hand, over again we are working with the data whose doesn't reflect the reality.
Transaction Isolation Isolation is one of the common ACID properties: Atomicity, Consistency, Isolation, and Durability. Isolation describes how changes applied by concurrent transactions are visible to each other. Each isolation level prevents zero or more concurrency side effects on a transaction:
I just found out one solution that worked for me
if (forceReadCommitted) {
this.session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
connection.setTransactionIsolation(2);
}
});
}
but you can notice that this is for the whole connection and not for a specific transaction. There might be better solutions still.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With