a different object with the same identifier value was already associated with the session

今天新增了几个表,用powerDesigner生成Hibernate代码后,在测试时发现报了这个错误:

 

com.sybase.orm.dao.DaoException: Fail to save persistentObject at com.sybase.orm.hibernate.dao.HibernateDaoImpl.save(HibernateDaoImpl.java:749) at com.kentech.chainsys.daoimpl.hibernate.strategyNumDaoImpl.save(strategyNumDaoImpl.java:30) at dorado.nanyang.strategyNum.strategyNumViewModel.doUpdateData(strategyNumViewModel.java:57) at com.bstek.dorado.view.ViewModelSupport.updateData(ViewModelSupport.java:930) at com.bstek.dorado.view.ViewModelSupport.handleUpdate(ViewModelSupport.java:944) at com.bstek.dorado.view.rpc.UpdateDataRPCHandler.internalExecute(UpdateDataRPCHandler.java:119) at com.bstek.dorado.view.rpc.AbstractRPCHandler.execute(AbstractRPCHandler.java:119) at com.bstek.dorado.view.smartweb.v2.ViewServiceController.doRPC(ViewServiceController.java:447) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.bstek.dorado.action.Controller.doDispatch(Controller.java:220) at com.bstek.dorado.action.Controller.internalDispatch(Controller.java:174) at com.bstek.dorado.action.Controller.internalDispatch(Controller.java:138) at com.bstek.dorado.action.Controller.invokeAction(Controller.java:113) at com.bstek.dorado.action.ActionHandler.invokeAction(ActionHandler.java:140) at com.bstek.dorado.action.ActionHandler.invokeAction(ActionHandler.java:130) at com.bstek.dorado.core.DoradoServlet.doGet(DoradoServlet.java:83) at com.bstek.dorado.core.DoradoServlet.doPost(DoradoServlet.java:107) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:49) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:64) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.bstek.dorado.core.FilterHandle.internalDoFilter(FilterHandle.java:328) at com.bstek.dorado.core.FilterHandle.doAgentRPCFilter(FilterHandle.java:276) at com.bstek.dorado.core.FilterHandle.doFilter(FilterHandle.java:142) at com.bstek.dorado.core.DoradoFilter.doFilter(DoradoFilter.java:69) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595) Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.kentech.chainsys.strategyNum#0] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:154) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514) at com.sybase.orm.hibernate.dao.HibernateDaoImpl.save(HibernateDaoImpl.java:743) ... 47 more Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.kentech.chainsys.strategyNum#0] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:154) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514) at com.sybase.orm.hibernate.dao.HibernateDaoImpl.save(HibernateDaoImpl.java:743) at com.kentech.chainsys.daoimpl.hibernate.strategyNumDaoImpl.save(strategyNumDaoImpl.java:30) at dorado.nanyang.strategyNum.strategyNumViewModel.doUpdateData(strategyNumViewModel.java:57) at com.bstek.dorado.view.ViewModelSupport.updateData(ViewModelSupport.java:930) at com.bstek.dorado.view.ViewModelSupport.handleUpdate(ViewModelSupport.java:944) at com.bstek.dorado.view.rpc.UpdateDataRPCHandler.internalExecute(UpdateDataRPCHandler.java:119) at com.bstek.dorado.view.rpc.AbstractRPCHandler.execute(AbstractRPCHandler.java:119) at com.bstek.dorado.view.smartweb.v2.ViewServiceController.doRPC(ViewServiceController.java:447) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.bstek.dorado.action.Controller.doDispatch(Controller.java:220) at com.bstek.dorado.action.Controller.internalDispatch(Controller.java:174) at com.bstek.dorado.action.Controller.internalDispatch(Controller.java:138) at com.bstek.dorado.action.Controller.invokeAction(Controller.java:113) at com.bstek.dorado.action.ActionHandler.invokeAction(ActionHandler.java:140) at com.bstek.dorado.action.ActionHandler.invokeAction(ActionHandler.java:130) at com.bstek.dorado.core.DoradoServlet.doGet(DoradoServlet.java:83) at com.bstek.dorado.core.DoradoServlet.doPost(DoradoServlet.java:107) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:49) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:64) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.bstek.dorado.core.FilterHandle.internalDoFilter(FilterHandle.java:328) at com.bstek.dorado.core.FilterHandle.doAgentRPCFilter(FilterHandle.java:276) at com.bstek.dorado.core.FilterHandle.doFilter(FilterHandle.java:142) at com.bstek.dorado.core.DoradoFilter.doFilter(DoradoFilter.java:69) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595)

 

怎么回事?

仔细检查后,发现原来在用powerdesigner设计oom时,设主键的时候,忘记设这一项了,如图所示:

 

这个地方不设置,导致了Hibernate配置文件的主键为

  <id name="id">
         <column name="ID" sql-type="INTEGER" not-null="true"/>
      </id>

实际是应为

     <id name="id">
         <column name="ID" sql-type="INTEGER" not-null="true"/>
         <generator class="identity">  
         </generator>
      </id>

 

其中:

indentity:采用数据库提供的主键生成机制。特点:递增。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值