We're updating the issue view to help you get more done. 

Hibernate Envers AuditReader ignores dedicated hibernate column type defined in audited entity

Description

I have defined an audited entity that uses a certain hibernate type on distinct column:

Holiday.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 @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; // ... omitted getters/setters }

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.

HibernateDao.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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

Environment

Windows 7, JDK 1.7.0_03, Webapp with Apache Tomcat 7.0.26

Status

Assignee

Lukasz Antoniak

Reporter

Sebastian Götz

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.2

Priority

Major