I have and audited entity with a foreign key to a class (which I dont want to audit):
@Entity @Audited public class CitaAgenda { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "reconocimiento_id") @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) private Reconocimiento reconocimiento; ... }
Also, Reconocimiento is an entity with an embedded property:
@Entity public class Reconocimiento { @Embedded private Enfermeria enfermeria; ... }
And the embeddable class is as follows:
@Embeddable public class Enfermeria { private boolean diabetes; ... }
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:
@Convert(converter=MyBooleanConverter.class) private boolean diabetes;
and...
@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; } }
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 this these cases. |
|