Hibernate Envers Audit tables are created with foreign key with the entity. Because of this I am not able to delete any entries from the entity tables.

Description

I have a table say "Employee" and that table entity is annotated with @Audited. So an "Employee_Aud" is created. "Employee_Aud" is having foreign key constraint to "Employee", because of this I am not able to delete any records from "Employee" table. I guess this is fixed in 5.2.11, but I am using 5.2.12 still Audit tables are created with FK constraint with Parent table. Please advice.

Environment

Dev

Activity

Show:
Chris Cranford
September 24, 2018, 2:29 PM

, any update on this for me?

Chris Cranford
December 18, 2018, 2:11 PM

, are you able to at least show me the mappings generically? You mentioned the entity has a self-referencing attribute, how did you map it with the @Audited and @NotAudited annotations?

I'd really like to understand your problem but there are a variety of reasons as to why you have this foreign-key being created and without any information to work on its going to be difficult to find a resolution for you. I'm going to leave this open for another 30 days at which point if I don't hear anything I'm going to proceed with closing this issue.

Kristina Heckelmann
March 20, 2019, 3:52 PM
Edited

Hi - I think I have the same problem, I have an entity, let's say RootLayer that has a bidirectional manyToOne relationship to a MiddleLayer entity. The MiddleLayer entity has a composite key consisting of a validFrom date and the backreference to RootLayer. In addition, the MiddleLayer has a bidirectional manyToOne relationship to LeafLayer. With this setup, I can not delete an existing RootLayer object and I get the following error indicating a relationship between the audit tables and the normal tables: Referential integrity constraint violation: "FKJBI4GFCQ01BAT36P8GP8VLOJ3: PUBLIC.LEAF_LAYER_AUD FOREIGN KEY(MIDDLE_LAYER_ROOT_LAYER_FK) REFERENCES PUBLIC.ROOT_LAYER(ID) (1)

I added a zip file with my use case, I hope it is understandable. I'm using hibernate version 5.2.18.Final.

Chris Cranford
March 21, 2019, 6:01 PM

, thanks for the test case; I'll check it out soon.

Chris Cranford
September 30, 2019, 8:30 PM
Edited

The demo provided by illustrated a bug that was not addressed as part of HHH-10667. Along with fixing the foreign-key constraint issue, I've addressed the outstanding bug as a part of this issue as well.

Assignee

Chris Cranford

Reporter

Arunprasad

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Worked in

5.2.12

Components

Affects versions

Priority

Major
Configure