JPA。批量更新为null

时间:2016-07-01 13:28:39

标签: java sql jpa null sql-update

我想通过简单查询使用两个整数参数进行批量更新:

    getEm().createQuery(
            " update" +
                    "   table " +
                    " set" +
                    "   DEADLINE = :deadline," +
                    "   PROLONGATION = :prolongation" +
                    " where" +
                    "   ID = :id")
            .setParameter("id", entity.getId())
            .setParameter("deadline", entity.getDeadline())
            .setParameter("prolongation", entity.getProlongation())

一切正常,没有空值。 当我传递null。我有例外:

2016-07-01 15:35:15,707 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-24) SQL Error: 932, SQLState: 42000
2016-07-01 15:35:15,710 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-24) ORA-00932: inconsistent datatypes: expected NUMBER got BINARY

我在日志中看到空值不是整数:

2016-07-01 15:35:15,690 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-24) binding parameter [1] as [INTEGER] - [1]
2016-07-01 15:35:15,693 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-24) binding parameter [2] as [VARBINARY] - [null]

我接下来读到: How to put 'null' into column using HQL?

更新 我的实体中的字段:

private BigDecimal id;

private Integer deadline;

private Integer prolongation;

0 个答案:

没有答案