NTyler
NTyler

Reputation: 1427

Perform action on transaction commit

We are using Hibernate as a JPA provider. When one of the Entities is updated, I need to perform some updates to Quartz schedules. Currently that code is invoked inside the update method for that Entity. However, the Quartz changes should only take effect if the transaction successfully commits.

I thought about implementing an Entity Listener, but I only want to perform these updates when the Entity is modified by a specific method, and I'm not sure if JPA Entity Listeners support Dependency Injection which I'd need to get a reference to the Quartz scheduler.

Is there any way to programmatically attach a callback for when the active transaction commits?

Upvotes: 1

Views: 1745

Answers (1)

Alan Hay
Alan Hay

Reputation: 23226

Have a look at Spring's TransactionSynchronizationManager.

See here for an example:

http://azagorneanu.blogspot.co.uk/2013/06/transaction-synchronization-callbacks.html

Upvotes: 3

Related Questions