首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

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

2012-10-26 
在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(回钦波老师)

热点排行