是不是那个原因啊,你的hibernate是纳入在spirng的事务中,是不是要把 spring的事务也设置成不让它自动提交
如果说不行的话就没办法了
先帮你顶了
up!
up!up!
如果说不行的话就没办法了
先帮你顶了
up!
up!up!
解决方案 »
- ibaits 3 oracle 一对一插入问题
- 哪位朋友使用过Struts2的REST插件,请教几个问题,谢谢
- weblogic启动不起来
- struts2条件查询异常乱码
- 本年最后一天,元旦快乐!散分!!!!¥200
- 用SSH2和Ajax做用户注册信息的校验,
- struts中使Validator检验的问题
- LDAP的问题
- hibernate的问题!
- mina2 16进制得到数据后再得不到数据了
- org.hibernate.LazyInitializationException:could not initialize proxy - the owning Session was closed
- weblogic.jdbc.common.OracleBlob在哪个jar里?
发现 如果把数据源写在Hibernate配置文件中,会有不同的结果:
System.out.println(session.connection().getAutoCommit()); //结果为false,与上面不同
//session.beginTransaction().commit(); //数据不会提交到数据库中,除非去掉注释,与上面不同
Hibernate配置文件:
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/mldn
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">MySQL</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="show_sql">true</property>
<property name="connection.autocommit">false</property> <!-- 在Hibernate中默认就是false -->
<mapping resource="vo/Student.hbm.xml" /></session-factory>
</hibernate-configuration>Spring配置文件:<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean><bean id="studentDao" class="vo.StudentDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>测试类:
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentDao studentDao = (StudentDao)context.getBean("studentDao");
Student student = new Student();
student.setName("测试");
studentDao.save(student);
}
}
那会不会是spring默认提交他了?
但数据会自动提交到数据库。
我就是这点不明白。:(
class="org.apache.commons.dbcp.BasicDataSource">
这个数据源的有个属性是: defaultAutoCommit:设置从数据源中返回的连接是否采用自动提交机制,默认值为 true;
应该把这个设置成false
<property name="connection.autocommit">true</property>