I need to audit updates, inserts and deletes, i'm using eclipselink as JPA provider. I need to store all modified data.
I tried to use @PrePersist for the merge but i don't know why, it is not called, and it's not possible to pass a object as my data before.
Other problem is that in update transactions i will need to store data as it was before and after the transaction to do a comparison, same in deleting, i need to store data that was deleted.
What is the best way to do this?
@Entity
@EntityListeners(FrotaListener.class)
@Table(name="frota" , schema="sap")
@NamedQuery(name="Frota.findAll", query="SELECT f FROM Frota f")
public class Frota implements Serializable {..}
public class FrotaListener {
@PrePersist
@PreUpdate
@PreRemove
private void beforeAnyOperation(Object object) {
System.out.println("teste");
}
}
try {
em.getTransaction().begin();
em.flush();
em.merge(frota);
em.flush();
em.getTransaction().commit();
} catch (Exception e) {
sqlErrorParse(e);
e.printStackTrace();
}finally {
em.close();
}
and FrotaListener is never called