org.hibernate.HibernateException: save is not valid without active transaction
来源:互联网 发布:店铺销售数据算法 编辑:程序博客网 时间:2024/05/21 06:57
I am creating JSF application and using some hibernate stuff in it. All I want to do is to save the entity into the database but I keep getting this exception:
org.hibernate.HibernateException: save is not valid without active transaction
At first I was getting this exception:
org.hibernate.HibernateException: No CurrentSessionContext configured!
Then I found that I need to add this into my hibernate configuration:
<property name="hibernate.current_session_context_class">thread</property>
This solved this issue but now the above one appears. I am saving entity into database like this:
public void create(T entity) { getSessionFactory().getCurrentSession().save(entity);}
My hibernate.cfg.xml file looks like this:
<hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/online_tests_management</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.current_session_context_class">thread</property> <mapping class="com.groupgti.onlinetests.management.db.Service"/> </session-factory></hibernate-configuration>
I am using:
Hibernate-4.1.4.Final
JDK 1.6
Tomcat 6
JSF 2.0
PrimeFaces 3.3.1
MySql
Does someone know where might be the problem?
You have to call session.beginTransaction()
public void create(T entity) { Session session=getSessionFactory().getCurrentSession(); Transaction trans=session.beginTransaction(); session.save(entity); trans.commit();}
0 0
- org.hibernate.HibernateException: save is not valid without active transaction
- org.hibernate.HibernateException: save is not valid without active transaction
- org.hibernate.HibernateException: save is not valid without active transaction at org.hibernate.co
- org.hibernate.HibernateException: createSQLQuery is not valid without active transaction
- org.hibernate.HibernateException: delete is not valid without active transaction
- org.hibernate.HibernateException: createSQLQuery is not valid without active transaction
- spring 管理 hibernate 事物,抛异常 org.hibernate.HibernateException: save is not valid without active transa
- Exception in thread "main" org.hibernate.HibernateException: save is not valid without active transa
- ssh整合报错org.hibernate.HibernateException: createQuery is not valid without active transaction
- 使用S2SH框架时,出现org.hibernate.HibernateException: createQuery is not valid without active transaction
- SSH 整合报org.hibernate.HibernateException: ...... is not valid without active transaction异常
- Hibernate 配置使用线程报错org.hibernate.HibernateException: createCriteria is not valid without active trans
- Exception in thread "main" org.hibernate.HibernateException: get is not valid without active transac
- spring声明式管理事务+ hibernate + save is not valid without active transaction
- spring+hibernate进行线程操作时异常:save is not valid without active transaction
- hibernate中: is not valid without active transaction
- hibernate错误:load is not valid without active transaction
- Hibernate SessionFactory getCurrentSession is not valid without active transaction
- 使用Struts2和jQuery EasyUI实现简单CRUD系统(五)——jsp,json,EasyUI的结合
- 设计一个栈,提供一个函数能够找出栈内最大的元素,时间复杂度为O(1)
- rsync 命令详解
- 贺利坚练习(1)
- 完美解决android Studio打开报错 https://code.google.com/p/android/issues
- org.hibernate.HibernateException: save is not valid without active transaction
- Flex4基础-组件定位和容器布局
- 为什么通信服务提供商需要实现SD-WAN
- 高精度开方
- YAHOO 14条优化原则
- LeetCode 题解(217) : Min Stack
- CABasicAnimation用法
- 23设计模式之适配器(Adapter)
- XML 数据挖掘,第 1 部分: 考察几种 XML 数据挖掘方法