This content has been marked as final. Show 1 reply
Database access inside events is allowed, whether JPA events or descriptor events, but you need to be careful. Basically you need to understand what you are doing and its affects and are on your own if you screw something up. You must keep in mind that the persistence context is in the process of a commit. So calling persist() or changing objects can have issues, the objects may not get inserted or changes applied depending on the event. Performing direct database access such as native SQL queries is probably safer, but you need to be careful of locks and violating database constraints. You can use insertObject within a UnitOfWork during write events, but you need to be careful.
Normally you would use the same transaction, if you created a new transaction/EntityManager/UnitOfWork, then you need to be careful or performance, and of deadlocking with yourself.