Executing an update/delete query 报错是因为没有事务,
解决办法1:在@Modifying后面加@Transactional
解决办法2:采用AOP声明式
<tx:advice id="dao" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="deleteByUserId*" read-only="false"/>
<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到session-->
<tx:method name="*" propagation="REQUIRED" /><!-- 他就是允许所有的方法都有session <tx:method name="*" propagation="REQUIRED" />-->
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethods" expression="execution(* com.hblb.develop.repository..*.*(..))"/><!--第二种 expression="execution(* com.service.*.*(..))" 。。代表service下的所有 -->
<aop:advisor advice-ref="dao" pointcut-ref="daoMethods" />
</aop:config>