-->
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.  [ 12 posts ] 
Author Message
 Post subject: time related problem
PostPosted: Wed Apr 07, 2010 4:42 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
hi there,

i got a problem with a special date here, an object contains a java.util.date like this:

Code:
   @Field(store=Store.YES)
   @DateBridge(resolution = Resolution.DAY)
   private    Date   datum       = null;


in my database there is one special entry, which has datum="2009-12-22 00:00:00.0".

If i'm building a range query like:
Code:
+datum:[20080407 TO 20091221]


i also get this named special entry in my result list, which shouldnt be there, or should it?
increasing the hour of the document didnt solve the problem. is there something special with this date?
rebuilding the index always maps "2009-12-22 00:00:00.0" to "20091221", which isnt the behaviour i expected here.

btw: still using hs 3.0.1


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 5:19 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you might have a problem with timezone settings, unfortunately converting a java.util.Date to a String-date representation depends on the timezone configured for the JVM - default to the server settings.

Imagine your server timezone is having a -1 hour compared to your database, in this case the datum "2009-12-22 00:00:00.0" would be interpreted as "2009-12-21 23:00:00.0", just as an example, which would be truncated to 2009-12-21.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 5:37 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
that was something i already thought about, so i increased the time to 1 am (2009-12-22 13:00:00.0) in the database and rebuild the index, but that didnt solve the problem.

(system.getproperty("user.timezone")) is tellin me, that my server is set to the right timezone)


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 5:40 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
that was something i already thought about, so i increased the time to 1 am (2009-12-22 13:00:00.0) in the database and rebuild the index, but that didnt solve the problem.

you could have more than a single hour of difference?

Quote:
(system.getproperty("user.timezone")) is tellin me, that my server is set to the right timezone)

is it matching the database timezone?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 6:20 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
sorry, my fault. meant 1pm, not 1am, not used to work with these kind of time namings :)

but i meanwhile recognized another issue, the class contais some other dates, which all mapped as timestamps in the hibernate mapping, just the one i mentioned above is mapped as a date, like this:

Code:
<property name="datum" type="date" column="DATUM"
         not-null="false" />

<property name="erstellDatum" type="timestamp"
         column="ERSTELL_DATUM" />
...


timezone of the db also already checked and as classified as the correct one.


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 6:35 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
now i discovered something really strange, i change the resolution of "datum" to Resolution.HOUR (from Resolution.DAY), rebuild the index, set up my query, and i wont get it as a result of the range query.
But, when i inspect my index with Luke, the entry for "datum" there is still 20091221, i dont get it, why it now wont appear in my result list. Strange one.


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 9:39 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
anybody? its a workaround ok, but it doesnt really solve the problem itsself


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Wed Apr 07, 2010 1:12 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
would you be able to provide a failing unit test?

it's hard to tell what's wrong

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Thu Apr 08, 2010 4:02 am 
Newbie

Joined: Thu Apr 01, 2010 9:47 am
Posts: 6
The @DateBridge annotation expects dates to be in the GMT format. So if the date in your database is stored in anything but GMT, things will break: your date is converted to a String as if it were GMT. Spefically, the DateTools functions that DateBridge uses internally cause this. So the x hours difference between your timezone and GMT may cause the string representation of the date to have another day than the actual date in your database!

Actually, I also encountered this problem earlier, and storing all our dates in GMT wasn't an option. Thus I ended up writing a custom bridge for date fields, which converts dates to string taking the timezone into account.
I think it would be a nice feature if the HS DateBridge could take timezones into account, since currently it breaks quietly if you don't provide a GMT date, which can be quite confusing.


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Thu Apr 08, 2010 4:31 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
... and storing all our dates in GMT wasn't an option

of course storing dates in GMT format is the only viable solution to make the index format consistent across regions and server reconfigurations.
I'd recommend to convert your range queries to use GMT formatted dates too, and verify that the Date conversion from database to java is fine.

Quote:
I think it would be a nice feature if the HS DateBridge could take timezones into account, since currently it breaks quietly if you don't provide a GMT date, which can be quite confusing.

feel free to open a feature request; if you could add a patch even better!

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Thu Apr 08, 2010 8:34 am 
Newbie

Joined: Thu Apr 01, 2010 9:47 am
Posts: 6
s.grinovero wrote:
of course storing dates in GMT format is the only viable solution to make the index format consistent across regions and server reconfigurations. I'd recommend to convert your range queries to use GMT formatted dates too, and verify that the Date conversion from database to java is fine.


Agreed, GMT is pretty much required if you have to share the index across regions. For a local application (or a 'master' server location) it can be convenient to work with the local time zone though. I don't think a local server would suddenly shift timezones (unless your country switches like the UK is considering... ;)

Always converting the database dates for querying seems like a hassle, but it's a good approach too. Hmm, I'll have to think about this a bit.


Top
 Profile  
 
 Post subject: Re: time related problem
PostPosted: Thu Apr 08, 2010 9:45 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Always converting the database dates for querying seems like a hassle

right but we could help on that by managing that in the new Query API, not sure if there's something related to Date already. There are experiments in current trunk, you might look there and early feedback and patches are really welcome.

Using GMT on the index is just safer, application correctness won't depend on server configuration mistakes, and you can also dump/restore the server across regions, you might find many use cases even if your app serves only a single region. (And then what if you have two different regions to serve?)
It definitely needs to contextualize the meaning of day at query time.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.