1

In our project we use envers to keep historical data for our entities. The historical data has a business value. As we know, the auditing occurs at the before completion phase, where exceptions are caught and not propagated.

The scenario is the following: imagine the entity change was successfully persisted but somehow, during the revision creation in the database, we get any sort of for example jdbc exception. What we noticed is that the entity was changed in the database without a revision created, causing a data inconsistency.

Is there any way with envers to have the whole transaction rollback due to failures during revision creation?

  • Under what environment scenario would you expect the exception *not* to be propagated? In fact, any Envers exception should rollback the transaction. – Naros Mar 21 '17 at 18:47
  • That's the opposite, we want the exception propagated. The reproduction steps are: modify the history table by removing one of the business columns so that it is not the same as the main entity one. Try to persist an entity. We noticed that the entity was successfully persisted despite the fact that it fails to create a revision in the history table due to a jdbc SQL exception. The exception was swallowed (TransactionSynchronizationUtils.triggerBeforeCompletion()) and just logged the error. – Newton Faria Jr. Mar 22 '17 at 14:30
  • This is why I asked about environment. At least from Hibernate's test suite, such a scenario does fail throwing an exception that we couldn't perform a beforeTransactionCompletion callback. See https://gist.github.com/Naros/6c8e81eee01dcbdee6c1d4d55fe59ddf for reference test. – Naros Mar 22 '17 at 15:59
  • We're using Spring Transaction instead. – Newton Faria Jr. Mar 22 '17 at 16:49
  • JTA or non-JTA environment? – Naros Mar 22 '17 at 16:55
  • The persistence-unit is configured as non-JTA (RESOURCE_LOCAL) . – Newton Faria Jr. Mar 22 '17 at 17:31
  • Feel free to join me at http://chat.stackoverflow.com/rooms/138756/hibernate-envers ... I've just tested this under spring and I get the same failure as I do in the test suite. – Naros Mar 22 '17 at 17:37
  • Can't really join it :( It's read only room for me. Not enough reputation – Newton Faria Jr. Mar 22 '17 at 17:52
  • My HipChat URL is posted in my profile you want to chat there then. This really sounds like a user setup/spring problem to me as I can't reproduce what you describe. What version of Spring/Hibernate/Envers? – Naros Mar 22 '17 at 18:02

0 Answers0