在SSH中经常抛出如上错误No Hibernate Session bound to thread, and configuration does not al

在SSH中经常抛出如下异常No Hibernate Session bound to thread, and configuration does not al在SSH中经

在SSH中经常抛出如下异常No Hibernate Session bound to thread, and configuration does not al
在SSH中经常抛出如下异常
Exception thrown: java.lang.IllegalStateException:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

解决方法如下:
多数是因为在持久层没有配置"事务"
错误的:
@Service

public class PersonServiceBean implements PersonService {
    @Resource SessionFactory sessionFactory;
    public void save(Person person) {
       sessionFactory.getCurrentSession().persist(person);//save()
    }
}
正确的
@Service

@Transactional
public class PersonServiceBean implements PersonService {
    @Resource SessionFactory sessionFactory;
    public void save(Person person) {
       sessionFactory.getCurrentSession().persist(person);//save()
    }
}
更多了解,更多需求请加QQ:444084929(回钦波老师)