【发布时间】:2013-11-27 15:41:17
【问题描述】:
我有以下想要更新的 JPA 实体:
@Entity(name = "EmployeeImpl")
@Table(name = "EmployeeImpl")
public class EmployeeImpl {
@Id
@Column(name = "employeeId")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ElementCollection
private List<String> phonenumber;
}
我以为我像这样使用namedQuery
@NamedQuery(name = "updateEmployee",
query = "Update EmployeeImpl e SET e.phonenumber :number WHERE e.id = :id")
但这不起作用:Exception Description: Error compiling the query [updateEmployee: Update EmployeeImpl e SET e.phonenumber = :number WHERE e.id = :id], line 1, column 28: invalid access of attribute [phonenumber] in SET clause target [e], only state fields and single valued association fields may be updated in a SET clause.
问题是,如何更新@ElementCollection?如果可能的话,我想用 jpql 查询来做。
【问题讨论】:
-
您要更新整个号码列表还是简单地添加一个号码?
-
我对两者都感兴趣。我发布的查询应该用新值替换所有数字。
标签: jpa jpql bulkupdate