It appears that when I save two instances of the same object, the first of which has a null Date property, Hibernate seems to translate the second instance's property between timezones, even though my databased column does not store timezone information.
My database in in EST and my JRE is in PST. My database is PostgreSQL 8.1, and I am using Hibernate 3.5.2.
Here's my test:
Code:
@Entity
public class RecordWithTime
{
private Date time;
private Long hibernateId;
public Date getTime()
{
return this.time;
}
public void setTime(Date time)
{
this.time = time;
}
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ids")
@GenericGenerator(name= "ids", strategy = "seqhilo")
@Column(name="hibernate_id")
public Long getHibernateId()
{
return this.hibernateId;
}
public void setHibernateId(Long id)
{
this.hibernateId = id;
}
}
public void testTimeZones()
{
Session session = HibernatePlugin.getDefault().openSession();
Transaction tx = session.beginTransaction();
RecordWithTime first = new RecordWithTime();
this.session.saveOrUpdate(first);
RecordWithTime second = new RecordWithTime();
second.setTime(new Date());
this.session.saveOrUpdate(second);
tx.commit();
second.setTime(new Date());
Transaction tx = session.beginTransaction();
this.session.saveOrUpdate(first);
this.session.saveOrUpdate(second);
tx.commit();
Transaction tx = session.beginTransaction();
RecordWithTime recordFromDb = session.get(RecordWithTime.class, second.getHibernateId());
assertEquals(new Date().getTime(), timeReportFromDB.getEndDate().getTime(), 100);
tx.commit();
}
The test fails, and it appears as if the record retrieved from the DB is three hours ahead.