0

When I retrieve a table from database using JPA, Date fields are decreased by a day. ex :

in database I have 08/12/2013, the result in my Date object is 07/12/2013 I think this is because days of Java Date Class (java.util.Date) starts from 0 to 30.

Here is my field as declared in my entity bean:

@Temporal(TemporalType.DATE)
@Column(name="PROG_DATE_DEMANDE")
private Date progDateDemande;

How to fix this problem ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ThunderPhoenix
  • 1,649
  • 4
  • 20
  • 47
  • How are you retrieving the day from progDateDemande? – Amin Abu-Taleb Sep 11 '13 at 09:26
  • What happens if you remove the `@Temporal` annotation? – Kevin Bowersox Sep 11 '13 at 09:28
  • 3
    Have you checked the time zones? There are many: Application server system TZ, TZ configured in Java of application server, database server system TZ and, maybe, TZ configured for the Oracle database. – Nikos Paraskevopoulos Sep 11 '13 at 09:29
  • @NikosParaskevopoulos How to configure Application server system TZ ? – ThunderPhoenix Sep 18 '13 at 13:58
  • The location of the settings will vary with the application server. Which one are you using? In any case, in order to set the JVM timezone, see [here](http://stackoverflow.com/questions/2493749/how-to-set-a-jvm-timezone-properly). You must find the configuration file of the your application server that contains this property. – Nikos Paraskevopoulos Sep 18 '13 at 14:10
  • @NikosParaskevopoulos I'm using Glassfish v3.1 – ThunderPhoenix Sep 19 '13 at 08:31
  • I set -Duser.timezone to "Europe/Paris" but I still have the same problem. – ThunderPhoenix Sep 19 '13 at 08:47
  • Make sure the server understands it. Have a JSP in your application print the result of the expression `java.util.TimeZone.getDefault()`. But note it may be due to the DB server timezone; or it may be another reason altogether. – Nikos Paraskevopoulos Sep 19 '13 at 09:03
  • Days in the Java Data Class do not start with 0, they start with 1. You confuse that with months, which indeed go from 0 to 11. I agree that this is most likely a timezone issue. Working with Oracle's DATE datatype and Java causes all kinds of funny effects. – Erich Kitzmueller Dec 28 '16 at 14:18

0 Answers0