hibernate - Rolling back and 2nd level collection cache -


i have hibernate 2nd level cache provided ehcache.

i have parent , child classes, parent.children cached collection.

when execute following code:

session session = datasessionfactory.opensession(); transaction tx = session.begintransaction(); parent parent = // load session child child = new child(); child.setparent(parent); session.saveorupdate(child); session.flush(); session.refresh(parent); tx.rollback(); session.close();  session = datasessionfactory.opensession(); tx = session.begintransaction(); parent = session.load(parent.class, parent.getid()); system.out.println(parent.getchildren()); 

the last line fails exception, trying load child not exist. after investigation found reason it's trying load child have been created , rolled in previous transaction.

what correct way configure caching, or roll transaction, collection cache cleared properly? don't want purge collection caches on rollback, thank you. looking way make hibernate or ehcache me minimal impact.

the hibernate transaction manager quite simple , described, seems doesn't handle case. reason simple: hibernate not trying implement jta itself, there plenty of jta providers out there. so, if using application server jboss as, can configure hibernate , ehcache use jta provider, handle situation.

also, believe entity being put cache "flush" method. so, if don't want use jta provider , unless "flush" needed, i'd remove part.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -