升级Oracle JDBC驱动程序后,Hibernate条件查询将引发异常

时间:2013-01-29 10:53:35

标签: hibernate jdbc oracle11g

我最近将Oracle 11g的JDBC驱动程序从ojdbc14.jar升级到ojdbc6.jar。 但是,以下条件查询现在不再起作用了:

criteria = ...
criteria = criteria.createAlias("contract", "contract")
    .add(Restrictions.disjunction()
    .add(Restrictions.isNull("contract.dateend"))
    .add(Restrictions.gt("contract.dateend", new Date())));

将结果限制为与仍在运行的合同关联的实体。

发生以下异常:

...
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2536)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
    at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
    at <<my method which creates the criteria query>>
    ... 61 more
Caused by: java.sql.SQLException: year out of range.
    at oracle.jdbc.driver.DateCommonBinder.setOracleCYMD(OraclePreparedStatement.java:19241)
    at oracle.jdbc.driver.TimestampBinder.bind(OraclePreparedStatement.java:19520)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:3137)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2355)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3579)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    ... 101 more

如前所述,旧司机仍然可以正常使用。相应的数据库列具有应该映射的类型DATE 通过Hibernate到java.util.Date

<property name="dateend">
    <column name="DATEEND" length="7" />
</property>

我是否必须更改此列的Hibernate映射?

提前致谢, 赖。

1 个答案:

答案 0 :(得分:2)

找到此行为的原因。类路径上有两个版本的JDBC驱动程序。我只更新了Tomcat lib文件夹中的lib。但是,我的war存档中仍有旧版本。这导致了错误