Search code examples
javapostgresqlglassfishpayara

payara server hosted eclipselink dates are being read from postgres an hour early


I am attempting to read a Timestamp value from a postgres database. I have tried various mappings, at the moment I am using the following mapping:

@Column(name = "Anlagedatum")
private Timestamp anlagedatum;

If I query the database using SQL, I get, for the first date 2015-02-27.

enter image description here

If I execute the JPA code using a scratch.java on my local machine, I get 2015-02-27

When the exact same query executes in the context of MY LOCAL Payara server, I get an incorrect date. The really wierd part is that my timezone is GMT +2, not +1.

The date returned by payara server is 2015-02-26 23:00:00

enter image description here

Why would payara server JPA change the date?
How do I change the mapping so that it gets the date stored without manipulation?


Solution

  • This look like a problem with the daylight saving time in your timezone.

    First thing to check is which column type you are using in your Postgresql Database.
    You should use: 'timestamp with timezone';

    If this is already the case you can try the following:

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name = "Anlagedatum")
    private Timestamp anlagedatum;
    

    If this doesn't help, I would try it with the 'Date' type in Java:

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name = "Anlagedatum")
    private Date anlagedatum;