hibernate - JPA java.util.Date issue -
i have date field in database value "27-aug-10 15:30:00". using jpa retrieve , set model object. in model object date 1 day "2010-08-28 04:00:00.0". when retrieved date should 27 aug 2010, coming 28 aug 2010 can please suggest me why retrieving 1 day.
import java.util.date; import javax.persistence.column; public class model { @column(name = "begin_date") private date startdate; public date getstartdate() { return startdate; } public void setstartdate(date startdate) { this.startdate = startdate; } }
the database default store timezone in. in retriving date out won't add timezone in. date being displayed gmt. @ using jodatime better date library.
i'll give example. need jodatime library , jadiratypes library persist jodatime dates hibernate.
http://mvnrepository.com/artifact/joda-time/joda-time/2.3
http://mvnrepository.com/artifact/org.jadira.usertype/usertype.jodatime/2.0.1
your code this:
@type(type="org.jadira.usertype.dateandtime.joda.persistentlocaldatetime") private localdatetime date;
this persist dates hibernate you.
i'm 90% sure jodatime supports adding timezone you. if worried, store them timestamps in database.
try changing jodatime above , let me know if have issues.
Comments
Post a Comment