I really have a weird issue now.
I just want to delete an entity.
I am also using Hibernate envers for auditing. So now I want to delete this entity.
Now I get following message.
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'succeed' cannot be null
So when I removed @Audit
from my table all of a sudden I was able to delete the entity.
Now I went to my entity_aud table and deselected NOT NULL for attribute succeed. Then I also again put @Audit
above my table.
Now it worked. So why if I want to just delete an entity, I get a NOT NULL error when using Hibernate Envers.
What is the reason for this.
When an entity is removed, Envers will also generate an audit entry for that operation. By default, entity data is not captured when a delete audit record is produced, so essentially Envers attempts to insert a row into the audit table that contains the Primary Key, Revision Number, and Revision Type. All the other columns will be inserted with null values.
Since your audit table had the succeed column specified as NOT NULL
, the delete throw an exception.
Besides the primary key, revision, and revision type columns in the audit table, all other columns should be created without the NOT NULL
specification for this reason, meaning they are allowed to be NULL. If you can reproduce Envers generating tables that do not adhere to this, please report it as a bug by attaching the entity model to the issue.
A configuration setting, org.hibernate.envers.store_data_at_delete
when set to true
will tell Envers to not only capture the entity's primary key, revision, and revision type, but all audited columns. This is not enabled by default because in general, the prior revision maintains that same state so replicating it is really unnecessary; however, some users prefer to have it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With