Uploaded image for project: 'Hibernate ORM'
  1. HHH-8602

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.2.2
    • Fix Version/s: 4.3.2
    • Component/s: hibernate-envers
    • Labels:
      None
    • Environment:
      Windows 7, JDK 1.7.0_03, Webapp with Apache Tomcat 7.0.26
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

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

      Holiday.java
      @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
      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

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: