I´m having trouble calling my EntityListener callback methods when using JPQL.
The none of the overriden methods get called.
They do work when using plain merges/inserts/updates (using the EM).
Is this a Eclipselink limitation?
I need this for auditing reasons, storing old and new values of each and every record changed on the DB.
Is there any other (easier) way of doing this?
You haven't mentioned what JPQL you are issuing that doesn't result in callback methods being called, so I assume it is the bulk update and delete statements. The JPA specification states in section 4.10 "The persistence context is not synchronized with the result of the bulk update or delete.
Caution should be used when executing bulk update or delete operations because they may result in
inconsistencies between the database and the entities in the active persistence context. In general, bulk
update and delete operations should only be performed within a transaction in a new persistence context
or before fetching or accessing entities whose state might be affected by such operations.",
This essentially means that JPA does not update the entities themselves, only the data in the database, and should be done before loading in entities so that the changes can be read in as well. Since the entities are unchanged, events cannot be fired for the changes. You will need to handle recording changes from bulk updates+deletes within the application.