用hibernate 加spring 插入不了数据

问题描述

我用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>

时间: 2024-08-11 09:41:41

用hibernate 加spring 插入不了数据的相关文章

插入多条数据回滚-hibernate 手动控制事务回滚失败

问题描述 hibernate 手动控制事务回滚失败 spring配置: 5201005100 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" />

关于hibernate 一对多插入数据的问题

问题描述 关于hibernate 一对多插入数据的问题 现在出现了一个问题, 主表和副表通过1对多的关系关联配置,所有的配置都完成了. 在做关联处理时,副表的查询是成功的,但是在对副表进行插入数据的处理时, 数据不能被插入,从打印的日志来看,副表的insert语句都没有被执行, 请问有没有人遇到过这种问题?是什么原因造成的?谢谢 解决方案 Hibernate一对多增删改查 解决方案二: 估计是hibernate配置时cascade的问题,如果是注解的看http://blog.csdn.net/z

spring-框架Spring和Hibernate 无法进行测试数据库的数据注入

问题描述 框架Spring和Hibernate 无法进行测试数据库的数据注入 解决方案 很奇葩的问题!报空指针异常,目测配置文件没有错误! 解决方案二: 很奇葩的问题!报空指针异常,目测配置文件没有错误! 解决方案三: 先看看passengerDaoTest.java的第15行是什么 解决方案四: 第十五行是:ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml"); 解决方案五

spring-jpa + Spring 2.5 表插入不了数据

问题描述 jpa + Spring 2.5 表插入不了数据 @Testpublic void runtest() { ApplicationContext ctx = new ClassPathXmlApplicationContext(""beans.xml""); ProductService productService = (ProductService) ctx.getBean(""productServiceImpl"&qu

HibernateTemplate().save()方法插入不了数据;

问题描述 开始没加this.getHibernateTemplate().flush();的时候插入不了数据,加了之后可以插入,网上搜索了下有人说是没自动提交事务,不知道是不是我spring里面的事务配置错了,帮我看看吧.public void saveUser(User user) {System.out.println(user);try {this.getHibernateTemplate().save(user);this.getHibernateTemplate().flush();}

【maven + hibernate(注解) +spring +springMVC】 使用maven搭建项目

研究,百度,查资料+好友帮助,使用MyEcplise2015工具,通过maven搭建hibernate+springMVC+spring的项目,数据库采用MySql5.5 不过使用的版本会在项目搭建过程中介绍. 大概就是下面的几个步骤: 1. 设计数据库,得到数据库 2.使用maven搭建项目,导入包的依赖 3.引入spring的配置信息,放在资源文件中 4.引入Log4j日志文件配置 5.配置hibernate 6.配置ehcache.xml 7.使用hibernate  tools生成实体

一个简单的hibernate与spring集成

下面介绍一下hibernate与spring的集成,这两个框架的集成关键在于 applicationContext.xml文件的配置,其实很简单的,但需要注意的是,导入包 时一定选择导入到webroot/web-inf/lib目录中,而且hibernate一般要在spring 之前导入,因为集成时要用到sessionFactory类, 一.初始化工作:新建一个项目,如(ssh),在此项目中导入对hibernate的支持 ,新建一个表sstest表,有字段id,username,password,

java-我的hibernate和spring 整合时getHibernateTemplate().find出现空指针问题

问题描述 我的hibernate和spring 整合时getHibernateTemplate().find出现空指针问题 Spring组件: class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 数据库连接参数信息 --> 方言,映射描述都没问题,/context:component-scan <bean id="txManager" class=&

spring mvc ajax请求数据后,前台根据返回的key如果跳转的别的jsp界面

问题描述 spring mvc ajax请求数据后,前台根据返回的key如果跳转的别的jsp界面 根据返回的data,在jsp前端进行跳转,有没有好的办法,还是可以通过配置就可以实现: window.location不太好使,可以跳转但是URL地址会显示具体的参数: 解决方案 参数你都放action里面了...那肯定显示了..fm表单放一个隐藏域存储你的cardList参数 <form id="fm" action="${}.../cardlist">&