我有以下要更新的 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 查询来做。