You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 16 Members of 4546 |
| Forum: Seam Users |
22. Jul 2008, 10:55 CET | Link |
Hi,
I have a requirement that requires some code to run (and manipulate entities that might cause a flush) just before the JPA/Hibernate session closes. Anyone any ideas on how to achieve this?
Thanks,
Sean
Maybe @PrePersist, @PreUpdate, @PreRemove could do the trick?
Nope. @PrePersist, @Pre.... won't do as I can't run a JPA Query and even if manipulating entities via relationships, a flush could occur resulting in possible recursion....
How about:
?
You inject(spring, spring/seam integration) or lookup(JNDI) a SessionFactory to your interceptor instance. If you try injection, inject the SessionFactory in a static field so that the separate Interceptor instance created on the persistence unit creation will have a hold to the same ref.
You can then open an independent session to perform your query inside your interceptor code.
You can add the below to activate your interceptor in your persistence.xml. You will have only 1 interceptor instance shared across all sessions to it has to be thread-safe.
To avoid possible recursive calls to your interceptor pass
when used inside the interceptor. EmptyInterceptor will override the default interceptor set in persistence.xml.All of this ain't very pretty but I believe it's a workable solution.
Hmm. Not too sure. Can't really use a second Session don't think this will fit for me.
Wondering whether a javax.transaction.Synchronization is the way forward....