Problem with callback call @PostPersist and ThreadLocalInstance
posted 2 years ago
I have an issue with my application which I believe is a bit beyond the basic knowledge. I have tried to find a solid solution but I am not being able to reach it.
I have a WEB application (Vaadin 6.8.5 + Tomcat 6 + Hibernate 3.5) where I need to store so-called ApplicationEvents (entity ApplicationEvent) which are created and inserted in the database, once certain events occur (i.e. after persisting a given set of entities and checking some conditions, I decide wether to fire or not the insertion of an ApplicationEvent which references another entity in the model. The idea works fine for my requirements but am facing a fundamental problem:
I need to use a threadlocalinstance in order to keep sort of SessionVariables for a given user, datalayer utilclasses and so on... My problem is that it is in that class (ThreadLocalInstance) where I want to keep a List with the applicationevents I need to store in the db once the main transaction is finished, but the problem is that the @PostPersist method (called during the persist transaction and responsible for scheduling in the List in the threadlocalinstance the ApplicationEvent's) seems to be executed inside a separate thread, hence not being able to access the threadlocalinstance and update the List.
So I am not being able to fulfill this requirement.