views:

70

answers:

1

Hi all,

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.

+1  A: 

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

Fried Hoeben
Yeah I've been considering that for a while now but I'm a bit leary about the "hidden" complexity of the AOP stuff. Maybe it's just one of those things that you're never really aware of what is going on just that it works. I will have to take another look at it.Does it noticeably impact performance? Or have any other undesirable side-effects in your experience?
Mike Q