`
huiqinbo
  • 浏览: 333234 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

在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(回钦波老师)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics