Transaction listeners? <possibly OT>

View: New views
3 Messages — Rating Filter:   Alert me  

Transaction listeners? <possibly OT>

by Syvalta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Is there any way to know what has changed in a transaction, something like a transaction listener? Something in lines of "transaction committed, entity x updated, entity y removed, entity z persisted". If I understood JPA specification correctly, entity listeners are called independent of the transaction, so if commit fails entity listeners for some of the entities might already got called.

Some use cases I have in mind: change log of the system configuration, applying configuration changes to a running system (think for example of mail server which can be configured from web ui).

Any ideas/comments/pointers really appreciated.

Re: Transaction listeners? <possibly OT>

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The JPA specification does not offer a solution to this, but EclipseLink has extended support for SessionEvents and UnitOfWorkChangeSets.

Refer to the SessionEventListener and SessionEventManager, which can be configured using a SessionCustomizer in your persistence.xml,
http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/SessionEventListener.html

http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/UnitOfWork.html#getUnitOfWorkChangeSet()

http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/changesets/UnitOfWorkChangeSet.html

Syvalta wrote:
Hi,

Is there any way to know what has changed in a transaction, something like a transaction listener? Something in lines of "transaction committed, entity x updated, entity y removed, entity z persisted". If I understood JPA specification correctly, entity listeners are called independent of the transaction, so if commit fails entity listeners for some of the entities might already got called.

Some use cases I have in mind: change log of the system configuration, applying configuration changes to a running system (think for example of mail server which can be configured from web ui).

Any ideas/comments/pointers really appreciated.

Re: Transaction listeners? <possibly OT>

by Syvalta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks James, that looks very useful.

James Sutherland wrote:
The JPA specification does not offer a solution to this, but EclipseLink has extended support for SessionEvents and UnitOfWorkChangeSets.

Refer to the SessionEventListener and SessionEventManager, which can be configured using a SessionCustomizer in your persistence.xml,
http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/SessionEventListener.html

http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/UnitOfWork.html#getUnitOfWorkChangeSet()

http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/sessions/changesets/UnitOfWorkChangeSet.html