These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Dropping timezones when some objects have no time.
PostPosted: Tue Mar 04, 2008 4:35 pm 
Newbie

Joined: Tue Mar 04, 2008 4:13 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.