代码:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-bean.xml");
HibernateTemplate hibernateTemplate = (HibernateTemplate)context.getBean("hibernateTemplate");
User user = new User();
user.setUname("wangwu");
user.setUpassword("ww2345");
hibernateTemplate.saveOrUpdate(user);
解决方法:在hibernate.cfg.xml中添加代码:
<property name="connection.autocommit">true</property>