hibernate的currentSession和多线程问题

1.spring管理hibernante的事务时,在service层开启多线程,在哪个service开启的子线程,则子线程的调用当前service的方法,不会开启事务,会报异常(No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here),因为没有事务开启无法通过getcurrentsession()获取session,但是可以通过opensession()获取session;
线程开启和线程中调用的方法应该不在同一个service上(mybatis上没有关系);
2.通常应该把多线程加在控制层不要加在service层,避免上述情况;

你可能感兴趣的:(多线程,Hibernate,session,事务)