我写了一个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;
}
你可以看到有一个名为"的发表名称" 。我想在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();
但是我收到了错误
&#34; java.lang.IllegalArgumentException:要遍历的节点不能为空!&#34;
我知道我在更新enum valur时遇到了什么问题。我该如何解决?
答案 0 :(得分:0)
使用您的(完全限定的)PublishIndicator枚举。 而不是PublishIndicator.PUBLISH值,如下所示:(假设您的PublishIndicator枚举在com.image包中),请将其用作com.image.PublishIndicator.PUBLISH