简体   繁体   中英

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

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 explicit 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.

尝试使用声明式事务处理方法 ,一次设置有点麻烦,但是之后您不必再担心事务处理了……

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM