Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Audit Log

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever a entity is changed or deleted we must write some information about the change to the audit log. One requirement is that we must also log changes through cascade actions. Therefore I use a entity listener that contains callback methods for create/update/delete actions. The problem is that I cannot inject the services to write the audit log data. Also I´ve seen that database actions in a callback method are forbidden by specification. What is the reason for that? Is there a better way to realize audit logging?
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you inject the services? What environment are you using? If you are inside an EJB container you could look up the needed service and write the audit log in it's own transaction. But that might lead to wrong logs when the "outer" transaction has to roll back.
What does the spec say about database actions in a callback method? Are they really forbidden or aren't you allowed to use the same session?
 
Sven Moschel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your fast response ;). Our application server is Glassfish with persistence provide eclipselink. The callback listener is within the ejb container but lookup for services doesn´t work (java:comp/env/...). I always get a name not found exception. The only thing that works is creating a new EntityManager instance with the EntityManagerFactory. With the entity manager I am able to write the logs but that is not very nice because we have Services for that.

What does the spec say about database actions in a callback method?


I doesn´t find that point in the spec at the moment but here is something from another page:

"To avoid conflicts with the original database operation that fires the entity lifecycle event (which is still in progress) callback methods should not call EntityMan­ager or Query methods and should not access any other entity objects"

I´m not sure if using callback methods is the best way to solve this problem.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whenever a entity is changed or deleted we must write some information about the change to the audit log.



Would Envers help? I haven't used it myself, so don't know if it goes well with EclipseLink. But probably it doesn't have any hard dependencies on Hibernate.
 
reply
    Bookmark Topic Watch Topic
  • New Topic