开发者

How can I use Spring HibernateOperations for simple operations with a implicit transaction?

开发者 https://www.devze.com 2022-12-14 03:15 出处:网络
I currently make heavy use of HibernateOperations in Spring for working with Hibernate.Some of the time I use a TransactionTemplate to demark a transaction explicitly.However sometimes I just want to

I currently make heavy use of HibernateOperations in Spring for working with Hibernate. Some of the time I use a TransactionTemplate to demark a transaction explicitly. However sometimes I just want to save/update a single object. If I just call hibernateOperations.save() with no explic开发者_Go百科it transaction active then it sort of works (I think auto-commit is coming in to play here) but it means certain events don't fire, like I have a hibernate event listener hooked into the commit transaction which I am missing in this circumstance.

What I am really looking for is a way to easily do something hibernateOperations.saveAndCommit() as I don't really want to have the whole TransactionTemplate + callback noise for simple things like a single save.

I could probably roll my own, just wondering if there's an existing solution/best practice for this.

I am not interested in driving my transactions via annotations at this point, I prefer the explicitness of the code.

Any suggestions welcome.

Cheers.


Try using the declarative transaction approach, it's a bit of a pain to set up once, but afterwards you hardly have to worry about transactions any more...

0

精彩评论

暂无评论...
验证码 换一张
取 消