oracle.sql.TIMESTAMPTZ与oracle.sql.TIMESTAMPTZ不兼容

时间:2019-07-12 13:27:36

标签: jpa eclipselink

我正在使用eclipseLink作为ORM从oracle数据库中获取值。我的表格中有一列,数据类型为 TIMESTAMP WITH TIME ZONE 对于该列,我得到

  

java.lang.ClassCastException:oracle.sql.TIMESTAMPTZ与不兼容   oracle.sql.TIMESTAMPTZ

当我打开类org.eclipse.persistence.platform.database.oracle.Oracle9Platform :: getTIMESTAMPTZFromResultSet()方法正在转换此数据类型。

我只想知道我在哪里错了,或者我缺少一些配置?

OJDBC依赖项

  <dependency>
      <groupId>oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.3</version>
      <scope>provided</scope>
  </dependency>

Oracle版本

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Eclipse链接版本

<dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>eclipselink</artifactId>
   <version>2.7.2</version>
   <scope>provided</scope>
</dependency>

服务器自由


例外

  

javax.persistence.PersistenceException:   java.lang.ClassCastException:oracle.sql.TIMESTAMPTZ与不兼容   oracle.sql.TIMESTAMPTZ在   org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:58)   在   org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:402)

     

由以下原因引起:java.lang.ClassCastException:oracle.sql.TIMESTAMPTZ   与oracle.sql.TIMESTAMPTZ不兼容,位于   org.eclipse.persistence.platform.database.oracle.Oracle9Platform.getTIMESTAMPTZFromResultSet(Oracle9Platform.java:238)   在   org.eclipse.persistence.platform.database.oracle.Oracle9Platform.getObjectFromResultSet(Oracle9Platform.java:205)   在   org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.getObject(Data   aseAccessor.java:1305),网址为   org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.fetchRow(DatabaseAccessor.java:1080)


EclipseLink方法

/**
     * INTERNAL:
     * Get a TIMESTAMPTZ value from a result set.
     */
    public Object getTIMESTAMPTZFromResultSet(ResultSet resultSet, int columnNumber, int type, AbstractSession session) throws java.sql.SQLException {
        TIMESTAMPTZ tsTZ = (TIMESTAMPTZ)resultSet.getObject(columnNumber);
        //Need to call timestampValue once here with the connection to avoid null point
        //exception later when timestampValue is called in converObject()
        if ((tsTZ != null) && (tsTZ.getLength() != 0)) {
            Connection connection = getConnection(session, resultSet.getStatement().getConnection());
            //Bug#4364359  Add a wrapper to overcome TIMESTAMPTZ not serializable as of jdbc 9.2.0.5 and 10.1.0.2.
            //It has been fixed in the next version for both streams
            Timestamp timestampToWrap = tsTZ.timestampValue(connection);
            TimeZone timezoneToWrap = TIMESTAMPHelper.extractTimeZone(tsTZ.toBytes());
            return new TIMESTAMPTZWrapper(timestampToWrap, timezoneToWrap, this.isTimestampInGmt);
        }
        return null;
    }

0 个答案:

没有答案