您的位置:首页 > 数据库

使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常

2011-11-28 16:42 459 查看
org.hibernate.HibernateException: No CurrentSessionContext configured!

没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:

1、本地事务

<property name="hibernate.current_session_context_class">thread</property>

2、全局事务

<property name="hibernate.current_session_context_class">jta</property>

这样就解决了!



如果在获得session 对象时使用的是 session = sessionFactory.getCurrentSession();

则此处可以改成[b] session = sessionFactory.openSession();[/b]

[b]这样就不用修改上面的配置文件了[/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: