wood burning stoves*
The moose likes Object Relational Mapping and the fly likes Hibernate doesn't use Oracle's native isolation levels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate doesn Watch "Hibernate doesn New topic

Hibernate doesn't use Oracle's native isolation levels

Ivan Koblik

Joined: Apr 22, 2008
Posts: 8
Hi All,

Could you please help me out with a problem that keeps bothering me. I use Hibernate with spring transaction management and Oracle 10g database.

Hibernate is initialized the next way:

Basically I get ObjectNotFoundException each time when
1. one read-only transaction gets an entity,
2. then some another concurrent transaction removes the entity from the database right after,
3. then the first one tries to lazily initialize a set in the entity, and not being capable of finding already removed rows throws the exception.

1 and 3 are executed in the same transaction, it seems like I have Read-Committed strategy. But, Oracle's read-only transactions are always serializable, which means that nothing in the database should change in scope of the transaction.

I wrote a small test to prove that hibernate doesn't behave:

So log shows that transactions that began before database was changed still see the changes.

I spent quite a while trying to figure out the way to force hibernate to use oracle's read-only or serialized transactions but failed.

I even tried to set hibernate.connection.isolation to 8, still didn't help.

Would appreciate any help!
Thanks in advance.
Ivan Koblik

Joined: Apr 22, 2008
Posts: 8
Forgot to mention:

Saving is also done through HibernateTemplate (this.getHibernateTemplate().saveOrUpdate(anObject);)
Ivan Koblik

Joined: Apr 22, 2008
Posts: 8
I also did a test that proves that Oracle actually does provide serializable access to read-only transactions.
Create a table with one column named ID and with three records 1,2,3.
In debugger execute next code up to -->.

execute in another window

Then run the code that was frozen in the debugger. c is equal to 3, access was really serializable!
[ September 11, 2008: Message edited by: Ivan Koblik ]
It is sorta covered in the JavaRanch Style Guide.
subject: Hibernate doesn't use Oracle's native isolation levels
Similar Threads
Hiberante transaction in Spring
calling a method in hibernate DAO through JMX export MBean
Controlling Hibernate Session with Spring
unsatisfied Dependancy exception
NPE at getHibernateTemplate( )