-
1. Re: Set non-shared Hibernate interceptor on JPA EntityManage
mjschehl Oct 26, 2007 11:46 AM (in response to mjschehl)Maybe I can use thread-safe Interceptors. Is it safe and okay to do the following?
public class Mynterceptor extends EmptyInterceptor { @In Identity identity; @PersistenceContext private EntityManager em; ... }
-
2. Re: Set non-shared Hibernate interceptor on JPA EntityManage
mjschehl Oct 26, 2007 12:03 PM (in response to mjschehl)I believe my thread-safe code is not okay because I want to create and save new entities inside of it.
To do that safely, I would need to create a new temporary EntityManager using the same JDBC connection and transaction.
How can I do that? Other than that, is the code safe and okay to do?public class MyInterceptor extends EmptyInterceptor { @In Identity identity; @PersistenceContext private EntityManager em; ... }
-
3. Re: Set non-shared Hibernate interceptor on JPA EntityManage
mjschehl Oct 29, 2007 3:03 PM (in response to mjschehl)I tried using the thread-unsafe interceptors in the persistance.xml by setting the property "hibernate.ejb.interceptor" and the code below.
I encountered two problems which I need help with:
1. The afterTransactionBegins never gets called
2. When the other methods get called, such as onSave, the identity and em don't get injected.
Could somebody please shed some light on this for me? I do not have to use JPA if that is a limitation.
Here is an explanation of what I am ultimately trying to achieve. If what I am trying to achieve can be done better in a different way, I would be okay with that.
Whenever a transaction starts, I need to create an Audit All entities annotated with @Historizable that are inserted or updated in that transaction must have their audit property set to that Audit updated on them. Additionally, for each insert, update, and delete, a HistoryEntry gets saved that stores each entity's class name, primary key, audit id, and toString(). The audit and history needs to be part of the main transaction so that it also rolls back if the transaction fails.public class MyInterceptor extends EmptyInterceptor { @In Identity identity; @PersistenceContext private EntityManager em; ... }
-
4. Re: Set non-shared Hibernate interceptor on JPA EntityManage
toby451 Dec 16, 2007 3:26 PM (in response to mjschehl)I am in need of auditlogging and versioning as well in the application we're building. And as always: the more elegant and slim solution, the better.
So I wonder: Did you ever solve this in a nice way?