-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate persists Date / Timestamp object 2 hours off
PostPosted: Thu Jun 15, 2006 3:50 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
Hibernate version:
Hi, I'm using Hibernate 3.1.3 with annotations on Oracle 9i. I have thoroughly found with no success in the forum and the Internet before submitting this post.

The problem I have is that when I persist a Date or Timestamp (I tried both) the database value is (exactly) 2 hours off. The way this is carrying out is really rare since I have indicated Hibernate neither to insert nor update this field. I want this field to be filled by the database automatically by setting the default value which turned to be CURRENT_TIMESTAMP.

The following Java snippet corresponds to the field causing this problem:

Code:
@Entity
@org.hibernate.annotations.Entity( dynamicUpdate = true )
@Table( name = "REQUEST_HISTORY", uniqueConstraints = {})
@SequenceGenerator( name="SEQ_GEN", sequenceName="SEQ_REQUEST_HISTORY" )
public class Request implements java.io.Serializable
{

....

    private Date        creation; // Also tried as java.sql.Timestamp

.....


    @Column( name = "CREATION", unique = false, nullable = false, insertable = false, updatable = false, length = 6 )
    @Temporal( TemporalType.DATE )
    public Date getArrivingTime()
    {
        return this.creation;
    }

    protected void setArrivingTime( Date creation )
    {
        this.creation = creation;
    }

.....


The database DLL for this field is:
Code:
Column name       Null?          Data type             Default
----------------------------------------------------------------------------
CREATION          Not null       TIMESTAMP(6)          CURRENT_TIMESTAMP



The Hibernate SQL log ( show_sql = true ):
Code:
Hibernate: select SIM_TB.SEQ_REQUEST_HISTORY.nextval from dual
Hibernate: insert into SIM_TB.REQUEST_HISTORY (STATE, TYPE, SHOWING_ID, DEDICATION, USER_ID, PLAYED, REQUEST_ID) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: update SIM_TB.REQUEST_HISTORY set STATE=?, TYPE=?, SHOWING_ID=?, DEDICATION=?, USER_ID=?, PLAYED=? where REQUEST_ID=?


As you can see this field shouldn't be involed in any write-operation done by Hibernate. Thus, I don't undertand why if do an insert by hand, the value is properly created (the DB date and time are fine) while using Hibernate the problem araises.

Do you have any idea of what might be happening here?

I live in Europe while the NLS_TERRITORY value of the DB is AMERICA. Could this affect in any way?

Any help you could provide would be really appreciated.

Thanks for your time! :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 8:37 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
I've found a posible solution although I don't think this is the way this issue must be sorted out.

I've had to change the involed Oracle field data type from TIMESTAMP to DATE. There must be some kind of bug that makes Hibernate to set two (or any other number) hours off the real local time. In addition, the bug is even bigger taking into account I annotated Hibernate in such a way that it shouldn't use the CREATION field in any write-operation. So, why is the time be inserted wrongly? And if the time is inserted wrongly, why does it retrieved as it is in the database (some hours off) and it doesn't fix the time off?

Well, I don't know yet why this is happening, but I know a possible way to sort it out. I think now it is the turn of Hibernate team to look into it.

Thanks a lot to the Hibernate team for such a great project, in spite of have some human bugs made by human pleople! :D


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 11:36 am 
Newbie

Joined: Fri Mar 03, 2006 4:13 pm
Posts: 4
I ran into something similar recently. The problem was that, in Oracle, CURRENT_TIMESTAMP is actually of type TIMESTAMP WITH TIME ZONE and we were storing it in a field of type TIMESTAMP. So just the time, without the time zone offset, was being recorded or something like that.

Solution was just to use SYSTIMESTAMP instead of CURRENT_TIMESTAMP for the default in Oracle.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 11:53 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
Thanks a lot Lance, I'll try and if I don't reply it will mean everything you said worked fine!

Thanks again!


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

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.