【问题标题】:Updating a one entity with another entity using JPQL update method使用 JPQL 更新方法用另一个实体更新一个实体
【发布时间】:2013-01-28 05:23:36
【问题描述】:

我尝试用 JPQL 中的另一个实体替换具有一对多关系的实体,但不知道如何正确表达 JPQL。

update PersonInstitution pi set pi.designation = (select d from Designation d where d.id = 50) where pi.designation.id = 34]

我想将所有 PersonInstitution 实体的一个名称(id 为 34)替换为另一个名称(id 为 50)。但它给出了错误。

我可以加载所有对象并对其进行编辑并将它们持久化,但我认为这是一种效率较低的方式。

我将 JPA 与 EclipseLink 2.0 一起使用

【问题讨论】:

    标签: jpa eclipselink jpql


    【解决方案1】:

    根据规范,它可能不适用于 JPQL。

    update_clause ::= UPDATE entity_name [[AS] identification_variable] SET update_item {, update_item}* 
    
    update_item ::= [identification_variable.]{state_field | single_valued_object_field} = new_value 
    

    您必须手动完成,否则可以尝试使用本机查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 2020-01-10
      • 1970-01-01
      • 2017-12-11
      • 2013-12-23
      相关资源
      最近更新 更多