我写了一个hql查询,我想在其中更新数据库中的枚举值,但我不知道如何更新枚举值。这是我的模型

@Entity
public class ImageInfo implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;

@Column(name = "ACTIVE")
private Integer active;

@Column(name = "NOTIFICATION_NUM")
private Integer groupNum;

@Column(name = "PUBLISHED_TIME")
@Temporal(TemporalType.TIMESTAMP)
private Date publishedTime;

@Column(name = "POSTED_TIME")
private Timestamp postedTime;

@Enumerated(EnumType.STRING)
private PublishIndicator publishIndicator;

}


您可以看到一个名为“ publishIndicator”的枚举字段。我想在hql查询中更新此字段。这是我的查询

session.createQuery("update ImageInfo img set img.active = 1
and img.publishIndicator = :publish where   img.active = 0  and
img.publishedTime <:publishedTime ").setParameter("publishedTime",
date).setParameter("publish", PublishIndicator.PUBLISH).executeUpdate();


但我遇到一个错误

“ java.lang.IllegalArgumentException:要遍历的节点不能为空!”

我知道我在更新枚举值时做错了什么我该如何解决?

最佳答案

使用(完全限定的)PublishIndicator枚举。
而不是PublishIndicator.PUBLISH值,而是这样的:(假设PublishIndicator枚举位于com.image包中),请将其用作com.image.PublishIndicator.PUBLISH

10-06 07:26