Issue
I'm using Hibernate Envers 5.3.7 and have the following Entity:
@Audited(withModifiedFlag=true)
public class MyEntity {
@Column(name = "item_condition")
private String condition;
As you can see the column name in the database differs from the property name. If I try to save the entity then envers throws an exception:
Cause: Unknown column 'condition_mod' in 'field list'
Query is: insert into MyEntity (revtype, item_condition, condition_mod,
Is there any way to control the modified flag column name? Something like to use the main column name defined in my entity or just define the modifiedFlag column name for a property?
Solution
You may want to take a look at the issue HHH-10398.
In Hibernate Envers 5.x and prior, the modified flags support has always build the mod-columns based on the actual property name rather than the @Column
annotation as its basis. This is why you're noticing that the insert fails, it expects your schema to have a column named condition_mod
.
As a workaround, you can explicitly specify the modified column's full name using the @Audited
annotation on the property until the above referenced issue is resolved and a strategy pattern implemented to support future and backward compatibility.
In your case, you'd annotate the property as follows:
@Column(name = "item_condition")
@Audited(withModifiedFlag = true, modifiedColumnName = "item_condition_mod")
private String condition;
In Hibernate 6, I plan to introduce a ModifiedColumnNameNamingStrategy
where there will be a legacy impl to support backward compatibility and an enhanced impl that will be able to allow you to simply specify the @Column
annotation and Envers will instead use that as a basis for the column name rather than the property.
But until that gets added, the workaround is the only alternative for 5.x and before.
UPDATE: A fix for HHH-10398 has been scheduled for inclusion in version 5.4.6.Final.
Answered By - Naros
Answer Checked By - Willingham (JavaFixing Volunteer)