2 Replies Latest reply: Dec 8, 2006 11:10 AM by 444462 RSS

    Listen to entity updates


      I want to be able to listen to entity updates/editions and deletions. Ideally I want to know the id of the objects affected. I also want these updates to be batched in transactions. So if 10 objects get updated in a transaction, I want to be notified of those 10 changes in one batch.

      Is this possible in TopLink JPA? And if so how?

        • 1. Re: Listen to entity updates

          The entity (descriptor) events will all be on a per instance basis. To accomplish what you want I would recommend using a SessionEventListener (see the extensions doc for config details).

          SessionEventListener.postCommintUnitOfWork or postCalculateUnitOfWorkChangeSet

          Within these events you can access the UnitOfWork (TopLink's transaction abstraction within the EntityManager) change-set or delta. This change-set will let you see all objects created, modified, or deleted within the transaction.

          The UnitOfWork contained within the event will have a UnitOfWorkChangeSet that you can interrogate for your purposes.

          • 2. Re: Listen to entity updates
            Can you provide a link to the "extensions doc" you refer to here?

            I'm trying to use SessionEventListener.postCalculateUnitOfWorkChangeSet and it doesn't appear to be giving me any references to new entities created within the unit of work. I can see them in my debugger (under newObjectChangeSets), but my call to getAllChangeSets() doesn't include these.