1

I am using Eclipselink 2.7.6, Oracle 12c, Payara 5 and I get a conversion exception when running a query.

The Entity definition is:

    @Column(name = "RUN_START_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date runStartTime;
    @Column(name = "RUN_STOP_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date runStopTime;

The persistence.xml file has the following properties:

<properties>
      <property name="eclipselink.logging.level" value="FINE"/>
      <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.Oracle12Platform"/>
      <property name="eclipselink.target-server" value="Glassfish"/>
    </properties>

And I have added the following dependency to my POM.xml:

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

Does anybody have any suggestions on what I could be doing wrong? I have seen a couple of other threads with regards to this but most don't have solutions/answers and the others seem to suggest what I have defined should be sufficient. I have this same code base working against MS SQL as well.

Update: I attempted a number of things based on comments including to use various types of Date/Timestamp formats the last of which was java.time.OffsetDateTime. I am getting the same error output:

Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.7.6.payara-p1): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [oracle.sql.TIMESTAMPTZ@38b7d502], of class [class oracle.sql.TIMESTAMPTZ], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[runStartTime-->ASR_RUN.RUN_START_TIME]] with descriptor [RelationalDescriptor(....ASRRun --> [DatabaseTable(ASR_RUN)])], could not be converted to [class java.time.OffsetDateTime].
    at org.eclipse.persistence.exceptions.ConversionException.couldNotBeConverted(ConversionException.java:81)
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToOffsetDateTime(ConversionManager.java:930)
    at org.eclipse.persistence.internal.helper.ConversionManager.convertObject(ConversionManager.java:123)
    at org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.convertObject(DatasourcePlatform.java:226)
    at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.getObjectValue(AbstractDirectMapping.java:611)
    at org.eclipse.persistence.queries.ReportQueryResult.processItemFromMapping(ReportQueryResult.java:186)

As the message is always the same just the class name changes, I am still thinking that I have something configured improperly. I made sure to use the following in my POM file to make sure I was using the latest Date formats:

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.oracle</artifactId>
            <version>2.7.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
        <!--dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </dependency-->
        <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8dms -->
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8dms</artifactId>
            <version>19.6.0.0</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.7.6</version>
        </dependency>

I tried various versions of the jdbc drivers as you can see from the commented version.

I'm still not sure what could be misconfigured.

kymnyth
  • 65
  • 1
  • 7
  • 1
    Don't use old `Date` rather use new classes of `java.time` – Eklavya Aug 17 '20 at 17:50
  • Nope, that didn't work: The type [class java.sql.Time] for the attribute [runEventTime] on the entity class [class com.crawford.proarchiver.papswebservice.entity.ASRRunEvent] is not a valid type for a temporal mapping. The attribute must be defined as java.util.Date or java.util.Calendar. – kymnyth Aug 17 '20 at 18:03
  • I am not saying about java.sql.Time, I saying about [java.time](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html) . And [here](https://www.baeldung.com/jpa-java-time#after-java-8) you get details about how to use. – Eklavya Aug 17 '20 at 18:16
  • OK, tried that and got this: Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.7.6.payara-p1): org.eclipse.persistence.exceptions.ConversionException Exception Description: The object [oracle.sql.TIMESTAMPTZ@3a24e26f], of class [class oracle.sql.TIMESTAMPTZ], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[runStartTime-->ASR_RUN.RUN_START_TIME]] with descriptor [RelationalDescriptor(....ASRRun --> [DatabaseTable(ASR_RUN)])], could not be converted to [class java.time.LocalDateTime]. Thanks for the suggestions! Keep them coming. – kymnyth Aug 17 '20 at 18:39
  • There is also type java.sql.Timestamp. IMHO even Java8 did not finalize its API. This is quite complex topic and you should read some theory about it before trying. Also note that Oracle datatype TIMESTAMP WITH TIMEZONE has few performance flaws. – ibre5041 Aug 17 '20 at 18:58
  • Thanks for the feedback @ibre5041 on TIMESTAMP WITH TIMEZONE, however the schema is legacy and I have to work with it the way it is. Do you have some suggestions on where I can find some reading to do on theory about this? – kymnyth Aug 17 '20 at 19:04
  • I am getting the same error no matter what the type is that I am converting too. I just tried java.sql.Timestamp. Is it possible I am missing a library or have it missconfigured so it doesn't have the correct jar to do the conversion? – kymnyth Aug 17 '20 at 19:19
  • I'm not Java developer (just Oracle DBA). Maybe you should check this: https://stackoverflow.com/a/54907501/836215 It is not related to Eclipselink JPA. It mentions new features in JDBC 4.2 and namespace java.time.* Those should overcome problems with the "old" datatypes. – ibre5041 Aug 17 '20 at 20:02
  • According to that you should not use LocalDateTime but rather OffsetDateTime . – ibre5041 Aug 17 '20 at 20:06
  • I noticed that as well and tried it. Unfortunately I am getting the same result. I have a feeling something is not configured properly. Thanks for your help. – kymnyth Aug 17 '20 at 20:19
  • Does anybody know which jar contains the conversion code from TIMESTAMPTZ to java.util.Date? Is it in the jdbc drivers or is their a seperate jar that needs to be specified? – kymnyth Aug 25 '20 at 21:42
  • Hi @kymnyth, did you find a solution to that problem? I am struggling with the same exception. – Irtaza Apr 16 '21 at 12:00

0 Answers0