【问题标题】:Hibernate/JPA : Include field in where clause of updateHibernate/JPA:在更新的 where 子句中包含字段
【发布时间】:2014-02-04 06:04:11
【问题描述】:

在 save() 时,Hibernate 执行 SQL 类似

update TABLE_A set COL_A=? , COL_B=? , COL_C=? where COL_PK=?

有什么办法可以改成:

update TABLE_A set COL_A=? , COL_B=?  where COL_PK=? and COL_C=?

这样做的原因是我们在 COL_C 上对表进行了分区,除非我们在 where 子句中使用它,否则它将查看所​​有分区。

【问题讨论】:

  • 使用休眠@DiscriminatorColumn定义分区可能是一个解决方案

标签: java oracle hibernate jpa


【解决方案1】:

在下面找到一个可以解释原理的sn-p。

int rowsUpdated = entityManager.createQuery("update YourEntity e"
    + " set e.columnA= :columnA"
    + " where e.columnPK = :columnPK"
    + " and e.columnC = :columnC")
    .setParameter("columnA", columnA)
    .setParameter("columnPK", columnPK)
    .setParameter("columnC", columnC)
    .executeUpdate();

【讨论】:

  • 感谢您的回答 - 我知道我可以编写更新查询。由于代码的结构方式,我希望它在对象上调用 save() 时发生。
猜你喜欢
  • 2021-01-21
  • 2012-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多