| Release 5.4.7 and beyond has introduced an issue in Envers (for me, at least) whereby some modified flag column values are always null which causes data constraint violations and an inability to persist entities and auditing info. This may be related to this issue: HHH-10398 I have a class with a number of @Audited annotations. The simple string value fields (name, description etc) work as expected and I can see in the logs that hibernate is persisting the modified flag column value correctly - true on create and false/true on update thereafter. The @Enumerated and @ManyToOne mappings modified column values are always null. I went back to release version 5.3.14.Final which works for me and every release up to and including 5.4.6 works. Below is an abbreviated class with the relevant annotations. There are other mappings that I have omitted for brevity - some audited OneToOne and OneToMany that work as expected.
@Entity
@Table(name = "matter")
@Audited()
public class Matter extends AbstractStringAssignedIdEntity {
private String name;
private String description;
private MatterClientSecurityOption clientSecurityOption = MatterClientSecurityOption.OPEN;
private MatterSecurityOption securityOption = MatterSecurityOption.DEFAULT_ACCESS;
private PracticeSettingsVersion practiceSettingsVersion;
public Matter() {
}
@Audited(withModifiedFlag = true, modifiedColumnName = "name_mod")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Audited(withModifiedFlag = true, modifiedColumnName = "description_mod")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, withModifiedFlag = true, modifiedColumnName = "settings_version_id_mod")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "settings_version_id", nullable = false)
public PracticeSettingsVersion getPracticeSettingsVersion() {
return practiceSettingsVersion;
}
public void setPracticeSettingsVersion(PracticeSettingsVersion practiceSettingsVersion) {
this.practiceSettingsVersion = practiceSettingsVersion;
}
@Audited(withModifiedFlag = true, modifiedColumnName = "security_option_mod")
@Enumerated(EnumType.STRING)
@Column(name = "security_option")
public MatterSecurityOption getSecurityOption() {
return securityOption;
}
public void setSecurityOption(MatterSecurityOption securityOption) {
this.securityOption = securityOption;
}
@Column(name = "client_security_option")
@Enumerated(EnumType.STRING)
@Audited(withModifiedFlag = true, modifiedColumnName = "client_security_option_mod")
public MatterClientSecurityOption getClientSecurityOption() {
return clientSecurityOption;
}
public void setClientSecurityOption(MatterClientSecurityOption clientSecurityOption) {
this.clientSecurityOption = clientSecurityOption;
}
}
Relevant configuration entries:
spring.jpa.properties.org.hibernate.envers.store_data_at_delete=true
spring.jpa.properties.org.hibernate.envers.audit_table_suffix=_aud
spring.jpa.properties.org.hibernate.envers.revision_field_name=rev
spring.jpa.properties.org.hibernate.envers.revision_type_field_name=revtype
Thanks, Craig |