【发布时间】:2017-02-15 16:34:25
【问题描述】:
Java 7
Oracle XE (11.2)
Spring Boot 1.3.5
EclipseLink 2.6.3
ojdbc7
我们在 Oracle 中有一个带有 TIMESTAMP 列的表。我们需要记录时区,因此我们将其切换为TIMESTAMPTZ (TIMESTAMP (6) WITH TIME ZONE)。我们还将模型属性从java.util.Date 转换为java.util.Calendar,并应用了@Temporal(TemporalType.TIMESTAMP) 注释。
@Temporal(TemporalType.TIMESTAMP)
private Calendar timeArrival;
所有内容均来自底部的 EclipseLink 文档here。看起来应该是相当无缝的。
进行这些更改后,我们无法访问该表(使用 JpaRepository.findAll() 方法进行测试)。我们得到了这个异常:
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]
无论我们做什么,这个错误都会发生,尽管我们的代码中不再有 Date 对象。我们尝试过的事情(以各种组合方式),但无济于事:
1) 放入@Converter/@TypeConverter注解指定object/db列类型
2) 从 ojdbc7 切换到 ojdbc6
3) 切换到 EclipseLink 2.5.0 以防这是最近出现的问题
4) 指定eclipselink.target-databasein application.properties (Oracle11)
5) 部署到 WebLogic 以使用 JNDI 数据源而不是直接 JDBC 连接
【问题讨论】:
-
尝试仅使用基本和临时注释指定 eclipselink.target-database,并显示完整的异常堆栈跟踪。您可能想尝试 EclipseLink 版本 >2.5.0,因为您显示的堆栈中的 conversionManager 略有变化 - 我不知道 2.5 有任何问题,但尝试一下也无妨。
-
@Chris -- 谢谢你 -- 在获取适当的堆栈跟踪以响应您的过程中,我想将我的目标数据库配置放在我的实际 Spring 配置类而不是应用程序中。属性,它触发了一个新的堆栈跟踪(无法找到
Oracle11Platform),最终导致我找到this page,表明我需要来自EclipseLink 的Oracle 扩展库。感谢您的帮助!
标签: java oracle jpa spring-boot eclipselink