|
I have defined an audited entity that uses a certain hibernate type on distinct column:
@Entity
@Table(name = "Holiday")
@Audited
@TypeDef(name = "hibernate_calendar_date", typeClass = org.hibernate.type.CalendarDateType.class)
public class Holiday extends OLEntity
{
public static final String PROPERTY_NAME = "name";
public static final String PROPERTY_DAY = "day";
public static final String PROPERTY_HOLIDAY_TYPE = "holidayType";
public static final String PROPERTY_CALENDAR = "calendar";
@Column(length = 60, name = "name", nullable = false)
@NotNull
@Size(max = 60)
private String name;
@Column(name = "day", nullable = false)
@NotNull
@Type(type = "hibernate_calendar_date")
private java.util.Calendar day = java.util.Calendar.getInstance();
@Column(name = "holidayType", nullable = false)
@NotNull
@Range(min = 1, max = Constants.NUM_HOLIDAY_TYPES)
private Short holidayType = 1;
@Column(name = "customHoliday")
@NotNull
private Boolean customHoliday = Boolean.FALSE;
@ManyToOne(fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "calendarId", updatable = false, nullable = false)
@NotNull
private Calendar calendar;
}
As a short explanation I want to mention that we use a custom Calendar type where ever an entity uses the java.util.Calendar as column type. But in this case we wanted to override this behavior with the default hibernate CalendarDateType which actually works for the none-envers part.
No when loading audit entities from the audit table using an AuditReader instance, envers uses the default registered hibernate type for java.util.Calendar (which actually is our custom one). It seems that envers does NOT evaluate the @Type annotation in this case.
if (getAuditReader().isEntityClassAudited(p_class))
{
int version = Math.max(0, p_version);
AuditQuery query = getAuditReader().createQuery().forRevisionsOfEntity(p_class, true, true);
List<T> entities = null;
AuditConjunction conjunction = AuditEntity.conjunction();
conjunction.add(AuditEntity.id().eq(p_id));
conjunction.add(AuditEntity.property(OLEntity.PROPERTY_VERSION).eq(version));
query.add(AuditEntity.revisionNumber().maximize().add(conjunction));
query.addOrder(AuditEntity.revisionNumber().desc());
entities = query.getResultList();
}
Any chance to force envers to a distinct type for a column?
Sincerely Sebastian
|