Hibernate原生SQL删除产生的问题:The executeQuery method must return a result set.

版权声明:_____________________不积跬步,无以至千里;不积小流,无以成江海。(转载若侵权,联系删除) https://blog.csdn.net/icecoola_/article/details/83752867

问题描述:
Hibernate 写原生SQL的时候出现这个问题

原先写法

String sql = "delete from t_table where 1=1;  ";
 em.createNativeQuery(sql);
		

按上面的写法产生了下面的报错,数据库的记录也没有得到删除

console报错信息:The executeQuery method must return a result set.

问题处理:
修改成如下,解决了问题

String sql = "delete from t_table where 1=1;  ";
		Query q = em.createNativeQuery(sql);
		q.executeUpdate();

=====================================
EntityManager使用方法

猜你喜欢

转载自blog.csdn.net/icecoola_/article/details/83752867