我試圖更新數據庫中的記錄,我得到這個錯誤org.springframework.orm.hibernate4.HibernateQueryException:不支持DML操作[更新]
org.springframework.orm.hibernate4.HibernateQueryException: Not supported for DML operations [UPDATE com.xxx.models.User u set u.notifiable = true WHERE u.emailAccess = :emailAccess AND u.isAdmin = false]; nested exception is org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [UPDATE com.xxx.models.User u set u.notifiable = true WHERE u.emailAccess = :emailAccess AND u.isAdmin = false]
這是我的HQL嘗試
@Modifying
public User updateUser(String emailAccess) {
String hql = "UPDATE User u set u.notifiable = true WHERE u.emailAccess = :emailAccess AND u.isAdmin = false";
return (User) _sessionFactory.getCurrentSession().createQuery(hql).setParameter("emailAccess", emailAccess).list();
}
經過研究,我在方法的頂部添加了@Modifying註釋,但錯誤仍然存在。請問有什麼可能是錯的?
在你的return語句中我看到** .list()**並且你只返回一個用戶。這是對的嗎? – duardito
使用'executeUpdate()'而不是'list' 同一問題在這裏: http://stackoverflow.com/questions/17622147/not-supported-for-dml-operations-with-simple-update-query – seiya