Search code examples
jpaspring-bootspring-dataweblogic

JPA Date is output to wrong date/time when running on Weblogic server, but displays correctly when running locally embedded Tomcat


I have a spring boot application using spring data to retrieve data from an Oracle database. When I run the code locally in embedded Tomcat, the date appears correctly. However, the same code when deployed to Weblogic server gives a completely different date/time result. I have confirmed that the timezone on the Weblogic server is the same as my local timezone (US/Eastern).

What is odd is that the minutes are being stripped out and always set to 00, and also the time difference between the correct date and the date displayed is unpredictable (one example is 16 hours behind, and with a different example, it's 19 hours)

jpa mapping:

import java.util.Date;
...
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "INITIAL_CREATE_DATE")
private Date initialCreateDate;

controller log statement:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm z");
...  
log.info("~~create date: " + medley.getInitialCreateDate() + " sdf " + sdf.format(medley.getInitialCreateDate()));

output from Weblogic (WRONG):

~~create date: Thu Oct 26 20:00:00 EDT 2017 sdf 10/26/2017 08:00 EDT 

output from local Tomcat and spring data unit tests (CORRECT):

~~create date: 2017-10-27 11:57:53.0 sdf 10/27/2017 11:57 EDT 

Two things that stand out to me (besides the date/time being totally wrong) 1. The time is missing the minutes 2. The format is different on the .toString() output for the date

Any help or ideas how I can further troubleshoot this problem are very much appreciated!


Solution

  • I figured my problem out - posting my answer, maybe it will help someone else.

    My "medley" object was not retrieved directly from the database here. It was retrieved by a job that then posted this medley object as JSON to this method here that outputs the date. While I still don't understand the odd date/time behavior, at least now I know the fix.

    My previous version of the code was using @Temporal(TemporalType.DATE) and serializing json as this...

    "initialCreateDate": "2017-10-27",
    

    which I don't understand why this was being converted to Thu Oct 26 20:00:00 - but at least I know that applying the @Temporal(TemporalType.TIMESTAMP) in my job fixed the problem. (i.e. updating the version of the repository code in pom.xml to the same version used by the service)

    This is the correct serialization of the date/time:

    "initialCreateDate":1509119873000