Hi all,
The application I am working on is using Hibernate 3.5.6-Final. The issue I am having is that named native queries do not seem to use the custom type converter I have setup to ensure that all Date's are UTC/GMT.
Code:
@Entity
@Table(name = "start_end_date")
@NamedNativeQueries({
@NamedNativeQuery(
name = "StartEndDate.findAll",
query = "SELECT start_date AS startDate, end_date AS endDate FROM start_end_date",
resultSetMapping = "StartEndDate.findAllMapping")
})
@SqlResultSetMappings({
@SqlResultSetMapping(
name = "StartEndDate.findAllMapping",
entities = {
@EntityResult(
entityClass = StartEndDate.class,
fields = {
@FieldResult(name = "startDate", column = "startDate"),
@FieldResult(name = "endDate", column = "endDate")
})
})
})
public class StartEndDate {
private Long id;
private Date startDate;
private Date endDate;
@Id
public Long getId() {
return id;
}
public void setId(final Long entityId) {
id = entityId;
}
@Type(name = "utcTimestamp")
@Column(name = "start_date")
@Temporal(TemporalType.DATE)
public Date getStartDate() {
return startDate;
}
public void setStartDate(final Date date) {
startDate = date;
}
@Type(name = "utcTimestamp")
@Column(name = "end_date")
@Temporal(TemporalType.DATE)
public Date getEndDate() {
return endDate;
}
public void setEndDate(final Date date) {
endDate = date;
}
}
If I use the JPA EntityManager to read the StartEndDate entity then everything is okay. However if I use the NamedNativeQuery then the start and end dates that are returned are basically the date/time in the DB with the machines timezone which isn't correct i.e. if the startDate DB DATE is "2012-10-05 14:00:00" and the machine that is running the application is using the EST timezone then using the NamedNativeQuery, the getStartDate method will return "2012-10-05 14:00:00 EST". I have added transient methods to the StartEndDate entity to basically take into account the offset between the machines timezone and UTC/GMT for this scenario but is there a better way to do this with Hibernate 3.5? I presume using Hibernate 3.6 registerHibernateType at bootstrap time would work if I upgraded to this version?
Thanks in advance