Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to audit JPA without Hibernate Envers
    primarykey
    data
    text
    <p>I need to <strong>make an audit module</strong> to my Java Web App. I use EclipseLink, not Hibernate (can't use Envers). I searched a lot some way to get the SQL or JPQL that JPA is executing, so I could log something like this:</p> <pre><code>System.out.println("User " + user + " from " + ip_address + " executed " + jpa_statement + " at " + new Date()); </code></pre> <p>Actually, I'll save this info into a history database's table. So I can easily retrieve this info any time I want. That's why "<strong>SHOW SQL</strong>" parameters are not enough to me. I really need the SQL string, so I can manipulate it at my source code.</p> <p>I found at JPA spec the <strong>EntityListener</strong> feature and thought it was the perfect place to put my logging code. For example, the postUpdate method could log the time the object was updated. But my problem is that I can't have the SQL the was executed.</p> <p>Here is an example of what I mean:</p> <pre><code>public class AuditListener { @PostUpdate public void postUpdate(Object object) { User user = (User)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user"); String ip_address = (User)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("ip_address"); String jpa_statement = object.getSQL(); System.out.println("User " + user + " from " + ip_address + " executed " + jpa_statement + " at " + new Date()); } } </code></pre> <p><strong>But "object.getSQL()" doesn't exists. So how can I get the SQL statement?</strong></p> <p>If anyone could point me into the right direction, I would appreciate!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload