Hibernate save()和insert()方法不能写入数据库的问题

session.save() getHibernateTemplate.save() 


  应用MyEclipse集成的Hibernate工具自动生成的代码,经常会遇到这种不写数据的问题.也就是当你执行一条增加或修改语句时,程序执行正常没有异常,查看sql语句确实执行了insert或update命令,可是当你查看数据库的时候会发现数据并没有同被增加或修改到数据库. 
  这种现象的原因是没有提交事务,因为MyEclipse自动生成的dao方法都没有提交的操作 


  有两种方法可以解决: 
   1.在hibernate.cfg.xml中增加属性: 
      <property name="connection.autocommit">true</property> 


   2.自己写或着修改dao方法,增加事务提交方法

展开阅读全文

请教hibernate问题,为何不能写入数据库

08-22

用hibernate中的表的映射,写入htxxbrnHtxxb p =new Htxxb();rn p.setHtbm(htbm);rn p.setHtxyh(htxyh);rn p.setBmxxb(bmxxb1);//对象为映射的表rn p.setWzxxb(wz);//......rn p.setZcxxb(zc);rnrn为何出现如下错误,究竟是什么地方的错误rnexception rnrnorg.apache.jasper.JasperException: could not insert: [com.Htxxb]rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrnroot cause rnrnorg.hibernate.exception.GenericJDBCException: could not insert: [com.Htxxb]rn org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)rn org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)rn org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)rn org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)rn org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)rn org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)rn org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)rn org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)rn org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)rn org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)rn app.create_dm.getpkid(create_dm.java:65)rn org.apache.jsp.jhgs_005fhtlr_005fbccg_jsp._jspService(jhgs_005fhtlr_005fbccg_jsp.java:163)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrn 论坛

求救hibernate 初级问题不能save数据

11-21

type Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjavax.servlet.ServletException: org.hibernate.AssertionFailure: InvocationTargetExceptionrn org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrnrnroot cause rnrnorg.hibernate.AssertionFailure: InvocationTargetExceptionrn org.hibernate.util.GetGeneratedKeysHelper.prepareStatement(GetGeneratedKeysHelper.java:49)rn org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:389)rn org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:76)rn org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1739)rn org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)rn org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)rn org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)rn org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)rn org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)rn org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)rn org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)rn org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)rn org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)rn org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)rn org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)rn org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)rn org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)rn org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)rn org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)rn org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:614)rn dao.TestDAO.save(TestDAO.java:31)rn service.Service.save(Service.java:27)rn com.ssh.struts.action.LoginAction.execute(LoginAction.java:56)rn org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrn 论坛

没有更多推荐了,返回首页