title: Saving List of Objects Throws Hibernate Exception
body: <p>When I am saving a <code>List</code> of objects by calling <code>saveListOfPageChooserElement</code>, it throws the below exception </p>
  
  <p>Whereas, when I am saving a single instance by calling <code>saveOrUpdate</code>, then it works fine.</p>
  
  <p>But to improve performance I want to save a List batch rather than single object at a time. </p>
  
  <p>Can anyone suggest what's the problem with saving a whole list at once?</p>
  
  <pre><code> List&lt;Abc&gt; listabc = widgetCopyDAO
                      .fetchabcByPageId(id);
  
  
      for (Abc abc: listabc ) {
                  abc.setLastUpdatedBy(null);
                  abc.setLastUpdatedOn(null);
                  abc.setCreatedBy(widgetCopyDTO.getUserName());
                  abc.setCreatedOn(new Date());
                  abc.setPageChooser(new PageChooser(chooser.getId()));
  
  
  
                  abc.setId(0l);
                  issuePageWidgetDAO.saveOrUpdate(abc);
              }
  //  widgetCopyDAO.saveListOfPageChooserElement(listabc);
  
  
  public void saveOrUpdate(Abc abc) {
          if (abc.getId() == 0) {
              Long id = (Long) this.getHibernateTemplate().save(
                      abc);
              abc.setId(id);
          } else {
              this.getHibernateTemplate().update(abc);
          }
      }
  
  
  public void saveListOfPageChooserElement(
              List&lt;Abc&gt; listabc) {
          this.getHibernateTemplate().saveOrUpdateAll(listabc);
  
      }
  </code></pre>
  
  <p>The exception is </p>
  
  <pre><code>org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.mct.model.Abc was altered from 138 to 0; nested exception is org.hibernate.HibernateException: identifier of an instance of com.mct.model.Abc was altered from 138 to 0
      at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
      at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
      at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
      at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
      at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1055)
      at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1048)
      at com.mct.dao.WidgetCopyDAO.fetchPageChooserWithImagesByChooser(WidgetCopyDAO.java:82)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
      at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:126)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at $Proxy58.fetchPageChooserWithImagesByChooser(Unknown Source)
      at com.mct.service.widgethelper.ChooserWidget.copyWidget(ChooserWidget.java:676)
      at com.mct.service.widgethelper.ChooserWidget.copyAllWidgets(ChooserWidget.java:634)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown 
  </code></pre>