File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Envers : How to delete entries from my audit table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Envers : How to delete entries from my audit table?" Watch "Hibernate Envers : How to delete entries from my audit table?" New topic
Author

Hibernate Envers : How to delete entries from my audit table?

Laurent Tonon
Greenhorn

Joined: May 10, 2010
Posts: 3
Hello everyone,

I am trying to remove all audit entries related to an entity when I delete this same entity.

I know this is against the principle of auditing but I don't want to keep an history of object that I delete.

To do that, I figured out that I have to create my own listener and override the onPostDelete method with a HQL query inside :



But a thing which is weird is when I delete an entity, the SQL generated looks like this :
Hibernate: delete from User_AUD where (id, REV)=(?, ?)


And the message I have is :
com.mysql.jdbc.JDBC4PreparedStatement@5bb966: delete from User_AUD where (id, REV)=(1, ** NOT SPECIFIED **)
May 10, 2010 4:47:28 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 07001
May 10, 2010 4:47:28 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: No value specified for parameter 2


So it's not working, I don't really have a clue on what's going on Why would I have to specify another parameter? my HQL query looks good though...

Any help would be appreciated

Thanks for your time folks.
Laurent Tonon
Greenhorn

Joined: May 10, 2010
Posts: 3
Ok I'm almost done with this for those who want to know.

Thanks to the creator of Hibernate Envers, Adam Warski, I quote :

"id" is a hibernate keyword for the id of an entity, whatever the names is; in case of audit entities, the id is composite and is called "originalId". Try:



But now, I also would like to delete entries related to audit table in my revinfo table.

If someone has a clue, let me know

Thanks.
Cyril Vnilam
Greenhorn

Joined: Nov 28, 2012
Posts: 1
In Hibernate 'REVINFO' table represents org.hibernate.envers.DefaultRevisionEntity.

So try a query like 'delete from org.hibernate.envers.DefaultRevisionEntity rev where rev.id=2'

If configured as 'org.hibernate.envers.track_entities_changed_in_revision as true', in this case revinfo is represented by org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity

So try a query like 'delete from org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity rev where rev.id=2'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Envers : How to delete entries from my audit table?