Search code examples
javajdo

JDO - Determine entities affected by transaction commit


I'm in the early stages of putting together a Java web project with a JDO based persistence layer and I found myself wondering about this.

If I start a transaction in my HTTPServlet and commit or rollback in the servlet before writing the response to the output stream, is there a way to get a list of objects (or just IDs) that were changed by the commit? If so, what would the performance be like?

Update:

I haven't tried this yet, but it seems that adding an InstanceLifecycleListener to the PersistenceManager would do the trick.


Solution

  • Adding an InstanceLifecycleListener to the PersistenceManager is working nicely so far. The only gotcha was not to omit the Classes[] parameter to addInstanceLifecycleListener. Instead if you want to listen to all changes, pass null explicitly.