不知道为什么,没有错误提示,hibernatetemplate.save(stu)就是不能保存实体,我的配置文件如下:
application.xml:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass"><value>org.hibernate.cfg.AnnotationConfiguration</value></property>
<property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="stuDao" class="StudentDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="stuService" class="StudentService">
<property name="stuDao" ref="stuDao"></property>
</bean>
<bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
</property>
<property name="target" >
<ref local="stuService"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
</beans>
hibernate.cfg.xml:
<property name="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.proxool.xml">proxool.xml</property>
<property name="hibernate.proxool.pool_alias">DBPool</property>
<property name="hiberante.defaultAutoCommit">true</property>StudentDaoImpl.java:
public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao{
public void saveStudent(Student stu) {
this.getHibernateTemplate().save(stu);
}
}StudentService.java:
public class StudentService {
private StudentDao stuDao;
public void saveStudent(Student stu){
stuDao.saveStudent(stu);
}
}
测试语句:
ApplicationContext ac=new FileSystemXmlApplicationContext("src/applicationContext.xml");
Student stu=new Student();
stu.setId(13);
stu.setName("aaa");
StudentService stuService=(StudentService)ac.getBean("stuService");
stuService.saveStudent(stu);运行结果:
Hibernate: insert into student (name, id) values (?, ?)
可数据库中就是没有记录。哪位知道原因啊,在线等待
application.xml:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass"><value>org.hibernate.cfg.AnnotationConfiguration</value></property>
<property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="stuDao" class="StudentDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="stuService" class="StudentService">
<property name="stuDao" ref="stuDao"></property>
</bean>
<bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
</property>
<property name="target" >
<ref local="stuService"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
</beans>
hibernate.cfg.xml:
<property name="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.proxool.xml">proxool.xml</property>
<property name="hibernate.proxool.pool_alias">DBPool</property>
<property name="hiberante.defaultAutoCommit">true</property>StudentDaoImpl.java:
public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao{
public void saveStudent(Student stu) {
this.getHibernateTemplate().save(stu);
}
}StudentService.java:
public class StudentService {
private StudentDao stuDao;
public void saveStudent(Student stu){
stuDao.saveStudent(stu);
}
}
测试语句:
ApplicationContext ac=new FileSystemXmlApplicationContext("src/applicationContext.xml");
Student stu=new Student();
stu.setId(13);
stu.setName("aaa");
StudentService stuService=(StudentService)ac.getBean("stuService");
stuService.saveStudent(stu);运行结果:
Hibernate: insert into student (name, id) values (?, ?)
可数据库中就是没有记录。哪位知道原因啊,在线等待
解决方案 »
- opentaps安装成功,但mysql里面有表没数据.
- 形如"http://www.xxx.com/test/abc"的链接
- 一个很急的问题!!!
- weblogic9.2部署JAVA web项目出错
- tomcat+spring如何配置连接池
- 新手jsp问题
- HTML和JSP矛盾吗?
- 用ant 预编译我的工程,请赐教
- 请问如何访问在tomcat\WEB-INF目录下的jsp页面?急
- javascript中以下代码是什么意思???
- Unable to initialize TldLocationsCache: XML parsing error on file /WEB-INF/lib/m
- 紧急求助,分数全给你了···
解决办法:你在hibernate.xml配置文件里加上
<property name="connection.autocommit">true</property> 变搞定