-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Search. Lucene index DATE
PostPosted: Thu Jun 11, 2009 11:42 am 
Newbie

Joined: Thu Jun 11, 2009 11:34 am
Posts: 7
Hi all!

I have a problem with dates in hibernate search.

I'm trying to index an object:

entityManager.index(myObject);

This object, contains a property of java.util.Date type. All fields are saved OK.

My problem is, for example:
- value of property date in my database: 02-06-2009 (dd/MM/yyyy format)
- value of property date in the index: 01-06-2009

Why my dates are one day less?

Thanks a lot


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Thu Jun 11, 2009 1:17 pm 
Newbie

Joined: Thu Jun 11, 2009 11:34 am
Posts: 7
Sorry, i see that this only happend when date is like 01-06-2009 00:00
and this not happend when date is like 01-06-2009 21:15

I start my VM with de argument -Duser.timezone=Europe/Madrid ...


Thx


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Thu Jun 11, 2009 1:18 pm 
Newbie

Joined: Thu Jun 11, 2009 11:34 am
Posts: 7
can anybody help me?


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Thu Jun 11, 2009 1:34 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I am pretty sure that's a timezone issue. If you look at the Hibernate Search code for the DateBridge you see it uses Lucene's DateTools which uses the UTC timezone.

How you handle this depends on your application and usecase. You might for example consider storing the dates in UTC in the database.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Fri Jun 12, 2009 3:41 am 
Newbie

Joined: Thu Jun 11, 2009 11:34 am
Posts: 7
hi!

Finally a found the solution, this is:

@Field(index = org.hibernate.search.annotations.Index.TOKENIZED,name="ftpublish",store=Store.YES,bridge=@FieldBridge(impl= FtpublishBridge.class))
public Date getFtpublish(){
...
}
In FtpublishBridge i get the GMT + 1 and dates ares saved correctly

Is this a good solution?

Thanks a lot


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Fri Jun 12, 2009 4:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I guess it works, but you might get into trouble when the timezone changes your application runs in. If you just statically add GMT+1 the whole application might not be 'portable'.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search. Lucene index DATE
PostPosted: Sat Jun 19, 2010 8:12 pm 
Newbie

Joined: Sat Jun 19, 2010 8:04 pm
Posts: 1
I also managed this problem by writing my own FieldBridge implementation.
I didn't have to add one additional hour!
Using your own FieldBridge causes hibernate to use the same time zone as the application,
so every think will be fine.

RGs.


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