问题描述
我用hibernate加上spring在dao里用getHibernateTemplate().save()插入数据。。控制台显示执行了insert语句。但数据库没有新增数据请大家帮帮吧
解决方案
解决方案二:
有没有出现错误啊,这样提问怎么回答?
解决方案三:
有用到事务管理吗会不会是事务回滚了
解决方案四:
你有提交事务吗?comit了吗?
解决方案五:
没有错误。。没用到事务
解决方案六:
DAo代码。。publicclassTestDaoextendsHibernateDaoSupport{//@Override//protectedClassreturnClass(){//returnOtest.class;//}publicTestDao(){}//增加方法publicIntegeradd(Otestot)throwsException{returnInteger.parseInt(super.getHibernateTemplate().save(ot).toString());}
解决方案七:
main.....方法publicstaticvoidmain(String[]args){//测试插入ApplicationContextcon=newClassPathXmlApplicationContext("/applicationContext.xml");TestBiztb=(TestBiz)con.getBean("testBiz");Otestotest=newOtest();otest.setOname("ssssssssssss");try{intid=tb.add(otest);System.out.println(id);}catch(Exceptione){e.printStackTrace();}
解决方案八:
是不是Spring的未知文件中对增加的方法设置了只读呢?
解决方案九:
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!----><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="configLocation"value="classpath:hibernate.cfg.xml"></property></bean><beanid="testDao"class="com.p.common.TestDao"><propertyname="sessionFactory"><reflocal="sessionFactory"/></property></bean><beanid="testBiz"class="com.p.biz.TestBiz"><propertyname="tDao"><reflocal="testDao"/></property></bean></beans>
解决方案十:
事务管理那块配置好了吗?比如:<beanid="transManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><propertyname="sessionFactory"><refbean="sessionFactory"/></property></bean><tx:adviceid="txAdvice"transaction-manager="transManager"><tx:attributes><tx:methodname="save*"propagation="REQUIRED"/><tx:methodname="del*"propagation="REQUIRED"/><tx:methodname="update*"propagation="REQUIRED"/><tx:methodname="*"read-only="true"/></tx:attributes></tx:advice><aop:config><aop:pointcutid="allManagerMethod"expression="execution(*com.lyis.service.impl.*.*.*(..))"/><aop:advisoradvice-ref="txAdvice"pointcut-ref="allManagerMethod"/></aop:config>