【问题标题】:Cant set a date to null again无法再次将日期设置为空
【发布时间】:2015-01-30 21:03:26
【问题描述】:

我正在尝试使用 hibernate 在 oracle 中将以前设置的日期字段设置为空,但是一旦“可空”列设置为日期,我就无法再次将其设置为空,因为我不知道如何表示在下面的查询中作为参数传递的空日期。

Query updateQuery;
updateQuery = em.createNativeQuery("UPDATE STATION SET MOD_DT = ?1 WHERE STATION_ID = ?2");
updateQuery.setParameter(2, stationId);
updateQuery.setParameter(1, null);
updateQuery.executeUpdate();

日志:

g! Dec 02, 2014 4:41:46 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 932, SQLState: 42000
<02-Dec-2014 16:41:46 o'clock EET> <Warning>   <org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <BEA-000000> <SQL Error: 932, SQLState: 42000>
Dec 02, 2014 4:41:46 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00932: inconsistent datatypes: expected DATE got BINARY

<02-Dec-2014 16:41:46 o'clock EET> <Error> <org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <BEA-000000> <ORA-00932: inconsistent datatypes: expected DATE got BINARY>

【问题讨论】:

    标签: java sql oracle hibernate date


    【解决方案1】:

    试试这个问题的解决方案: similar question

    setParameter 有 3 个参数,其中一个参数是值的类型

    【讨论】:

      【解决方案2】:
      Query updateQuery;
      updateQuery = em.createNativeQuery("UPDATE STATION SET MOD_DT = null WHERE STATION_ID = ?1");
      updateQuery.setParameter(1, stationId);
      updateQuery.executeUpdate();
      

      这里有一些信息:https://hibernate.atlassian.net/browse/HHH-9165

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-19
        相关资源
        最近更新 更多