1

我最近将 Oracle 11g 的 JDBC 驱动程序ojdbc14.jarojdbc6.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 映射?

在此先感谢,雷纳。

4

1 回答 1

2

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

于 2013-01-30T09:26:01.743 回答