我是hql的新手,因此在根据电子邮件进行匹配时尝试删除完整的行。

以下是我尝试过的。

我仍然遇到持久性异常。

public void unsubscribeEmailList(EmailListDto dataList) {
    EmailList e =new EmailList(dataList);
    Query q =sessionFactory.getCurrentSession().createQuery("delete from EmailList where email=:e");
q.setParameter("e", dataList);

    int i=q.executeUpdate();
System.out.println(i);
    }


类别EmailList是

@Entity
@Table(name = "email_list")
public class EmailList implements Serializable {



private static final long serialVersionUID = 1L;
private Integer           id;
private String            email;


public EmailList(EmailListDto dto)
{
    this.email=dto.getEmail();

}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}
 @Column(name = "email", nullable = false)
 public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}


}

最佳答案

试试这个:

q.setParameter("e", e.getEmail());

07-24 21:41