I have and audited entity with a foreign key to a class (which I dont want to audit): {code} @Entity @Audited public class CitaAgenda { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "reconocimiento_id") @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) private Reconocimiento reconocimiento; ... } {code} Also, Reconocimiento is an entity with an embedded property: {code} @Entity public class Reconocimiento { @Embedded private Enfermeria enfermeria; ... } {code} And the embeddable class is as follows: {code} @Embeddable public class Enfermeria { private boolean diabetes; ... } {code} Now, when I bring the data from the revisions and fetch CitaAgenda, I get a "Can not set boolean field ...Enfermeria.diabetes to null value".
To solve this problem I had to use a Converter: {code} @Convert(converter=MyBooleanConverter.class) private boolean diabetes; {code} and... {code} @Converter public class MyBooleanConverter implements AttributeConverter<Boolean, Integer>{ @Override public String convertToDatabaseColumn(Boolean value) { if (Boolean.TRUE.equals(value)) { return Integer.valueOf(1); } else { return Integer.valueOf(0); } }
@Override public Boolean convertToEntityAttribute(Integer value) { if(value != null && value.equals(1)){ return Boolean.TRUE; }
return Boolean.FALSE; } } {code} Link to Stackoverflow question: https://stackoverflow.com/questions/41872694/hibernate-envers-audit-embedded-with-basic-types-inside-throws-cannot-set-field
I have already solved my problem but I was told to open an issue to avoid the need of using a Converter to deal with these cases. |
|