请问关于spring事务管理的怪有关问题,事务没有自动提交。大哥们请帮帮忙
请教关于spring事务管理的怪问题,事务没有自动提交。大哥们请帮帮忙!
最近想要搭建一个spring和hibernate的系统,一切准备就绪,但是在测试的时候发现了个怪问题。
问题是这样的,代码可以正常运行,但是测试数据入库时发现不调用testDAO.getHibernateTemplate().getSessionFactory().close();这一句代码的话,在数据库里就查不到数据;调用这句之后就可以正常入库了。
实在是几天没搞定,想请各位大哥帮帮忙指点一下。
运行环境是:
JDK1.6
spring3.0(由myeclipse8.5自动导入的)
hibernate3.3(由myeclipse8.5自动导入的)
oracle 10g_r2
先上测试代码:
1、调用main类
2、manage类
3、applicationContext.xml
最近想要搭建一个spring和hibernate的系统,一切准备就绪,但是在测试的时候发现了个怪问题。
问题是这样的,代码可以正常运行,但是测试数据入库时发现不调用testDAO.getHibernateTemplate().getSessionFactory().close();这一句代码的话,在数据库里就查不到数据;调用这句之后就可以正常入库了。
实在是几天没搞定,想请各位大哥帮帮忙指点一下。
运行环境是:
JDK1.6
spring3.0(由myeclipse8.5自动导入的)
hibernate3.3(由myeclipse8.5自动导入的)
oracle 10g_r2
先上测试代码:
1、调用main类
package test;
import www.am8.manage.TestManageImpl;
public class SSHTest {
public static void main(String args[])
{
TestManageImpl tmi=new TestManageImpl();
tmi.shiwuSaveTest();
}
}
2、manage类
package www.am8.manage;
import java.util.Calendar;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import www.am8.iface.TestManage;
import www.am8.pojo.Test;
import www.am8.pojo.TestDAO;
public class TestManageImpl implements TestManage {
private TestDAO iTestDAO;
public TestDAO getiTestDAO() {
return iTestDAO;
}
public void setiTestDAO(TestDAO iTestDAO) {
this.iTestDAO = iTestDAO;
}
public void shiwuSaveTest() {
Resource res =new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(res);
//从BeanFactory获取UserDAO
TestDAO testDAO = (TestDAO) factory.getBean("TestDAO");
Test t = new Test();
Calendar c = Calendar.getInstance();
t.setTestId(21);
t.setShiJian(c.getTime());
t.setVar2("中文!!");
t.setChangZhengShu(23551);
t.setShiJian2("");
testDAO.save(t);
//testDAO.getHibernateTemplate().getSessionFactory().close();
}
}
3、applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans