Search code examples
javaoraclejpaspring-booteclipselink

Can't get Calendar object from Oracle TIMESTAMPTZ column with EclipseLink


Java 7
Oracle XE (11.2)
Spring Boot 1.3.5
EclipseLink 2.6.3
ojdbc7

We have a table in Oracle with a TIMESTAMP column. We gained a need to record a timezone, so we switched it to TIMESTAMPTZ (TIMESTAMP (6) WITH TIME ZONE). We also converted the model attribute from java.util.Date to java.util.Calendar, and applied the @Temporal(TemporalType.TIMESTAMP) annotation.

@Temporal(TemporalType.TIMESTAMP)
private Calendar timeArrival;

All that is from the EclipseLink documentation here, at the bottom. It looks like it should be fairly seamless.

After making these changes, we cannot access that table (using the JpaRepository.findAll() method for testing). We get this exception:

Exception Description: The object [oracle.sql.TIMESTAMPTZ@6b2a085f], of class [class oracle.sql.TIMESTAMPTZ], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[timeArrival-->TRIP_LEG.TIME_ARRIVAL]] with descriptor [RelationalDescriptor(<my-package>.data.model.TripLeg --> [DatabaseTable(TRIP_LEG)])], could not be converted to [class java.util.Date].
    at org.eclipse.persistence.exceptions.ConversionException.couldNotBeConverted(ConversionException.java:75) ~[org.eclipse.persistence.core-2.5.0.jar:na]
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToUtilDate(ConversionManager.java:788) ~[org.eclipse.persistence.core-2.5.0.jar:na]
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToCalendar(ConversionManager.java:375) ~[org.eclipse.persistence.core-2.5.0.jar:na]
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObject(ConversionManager.java:112) ~[org.eclipse.persistence.core-2.5.0.jar:na]

No matter what we do, that error is happening, despite there being no Date objects in our code anymore. Things we have tried (in various combinations), to no avail:

1) Putting in @Converter/@TypeConverter annotations to specify the object/db column types

2) Switching from ojdbc7 to ojdbc6

3) Switching to EclipseLink 2.5.0 in case this was a recently developing issue

4) Specifying the eclipselink.target-databasein application.properties (Oracle11)

5) Deploying to WebLogic to use a JNDI datasource instead of a direct JDBC connection


Solution

  • Sigh. My problem was I had the wrong dependencies.

    I originally had:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.6.4</version>
    </dependency>
    

    This worked fine for normal usage over a couple of days, until I introduced Oracle's TIMESTAMPTZ into my system. That means I needed the Eclipselink Oracle extensions jar:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.oracle</artifactId>
        <version>2.6.4</version>
    </dependency>
    

    Now that I've added that, everything is working again without any extra configuration or annotations. My model field is just:

    private Calendar timeArrival;