【发布时间】:2018-11-01 01:40:08
【问题描述】:
尊敬的 stackoverflow 社区,
我不确定为什么下面的代码没有更新我的数据库数据,但是从休眠日志中获取查询似乎可以工作......
我正在使用 Hibernate 5.2.12.Final
这是我的全部功能:
EntityManager em = Utils.initEntityManager();
em.getTransaction().begin();
em.persist(receptacle);
em.createNativeQuery("UPDATE product_item pi"
+ " JOIN ereturn er ON pi.ereturn = er.id "
+ "SET pi.receptacle = :receptacle "
+ "WHERE pi.returnAction = :returnAction "
+ "AND er.destination = :destination "
+ "AND er.status = 'RECEIVED'")
.setParameter("receptacle", receptacle.getId())
.setParameter("returnAction", receptacle.getReturnAction())
.setParameter("destination", receptacle.getDestination().getId())
.executeUpdate();
em.getTransaction().commit();
em.close();
这是来自休眠的日志
19:47:29,048 DEBUG [org.hibernate.SQL] -
UPDATE
product_item pi
JOIN
ereturn er
ON pi.ereturn = er.id
SET
pi.receptacle = ?
WHERE
pi.returnAction = ?
AND er.destination = ?
AND er.status = 'RECEIVED'
Hibernate:
UPDATE
product_item pi
JOIN
ereturn er
ON pi.ereturn = er.id
SET
pi.receptacle = ?
WHERE
pi.returnAction = ?
AND er.destination = ?
AND er.status = 'RECEIVED'
19:47:29,049 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [1] as [BIGINT] - [20]
19:47:29,049 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [3] as [BIGINT] - [148375]
19:47:29,049 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [2] as [VARBINARY] - [RETURNTOCLIENT]
我从日志中获取相同的查询,替换参数并在我的 mysql 控制台中运行它...查询有效!!!
问题:为什么上面的更新查询运行时mysql没有改变任何数据?
非常感谢
【问题讨论】:
标签: mysql hibernate sql-update nativequery