Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Laurent Tonon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic