title: can't understand why i didn't got exception using jsp, but got it with velocity?
body: <p>I have a spring mvc project.For views firstly i used jsp and it worked fine, but then i wanted to use velocity and got exception.Both views are similar except of syntax.I can't understand why it happens. That's my jsp:</p>
  
  <pre><code>&lt;form:form action="updateDepartament" modelAttribute="editDepartament" method="POST"&gt;            
           &lt;table&gt;            
              &lt;tr&gt;
                  &lt;td&gt;Id:&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="departamentId" readonly="true"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;spring:message code="label.title"/&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="title"/&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:errors path="title"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
           &lt;/table&gt;
  
           &lt;input type="submit" value="submit"&gt;               
   &lt;c:if test="${! empty editDepartament.depart_Employeers}"&gt;                        
                      &lt;table&gt;                            
                          &lt;th&gt;Id&lt;/th&gt;                            
                          &lt;th&gt;&lt;spring:message code="label.firstName"/&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;spring:message code="label.lastName"/&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;spring:message code="label.salary"/&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;spring:message code="label.birthdate"/&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;spring:message code="label.active"/&gt;&lt;/th&gt;                          
                          &lt;tr&gt;
                              &lt;c:forEach var="empl" items="${editDepartament.depart_Employeers}" varStatus="status"&gt;
                                  &lt;tr&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].id" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].firstName" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].lastName" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].salary" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].birthday" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;form:input path="depart_Employeers[${status.index}].active" readonly="true"/&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;a href="deleteEmployee/${empl.id}"&gt;&lt;spring:message code="label.delete"/&gt;&lt;/a&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/c:forEach&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/c:if&gt;
          &lt;/form:form&gt;
  </code></pre>
  
  <p>And this's my velocity template:</p>
  
  <pre><code>&lt;form action="updateDepartament"  method="POST"&gt;
          #springBind("editDepartament")
           &lt;table&gt;            
              &lt;tr&gt;
                  &lt;td&gt;Id:&lt;/td&gt;
                  &lt;td&gt;#springFormInput("editDepartament.departamentId" 'readonly="true"')&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;spring:message code="label.title"/&gt;&lt;/td&gt;
                  &lt;td&gt;#springFormInput("editDepartament.title" "")&lt;/td&gt;
                  &lt;td&gt;#springShowErrors("" "")&lt;/td&gt;
              &lt;/tr&gt;
           &lt;/table&gt;            
           &lt;input type="submit" value="submit"&gt;                    
                  #if(!$editDepartament.depart_Employeers.isEmpty())
                       &lt;table&gt;
                          &lt;th&gt;Id&lt;/th&gt;                            
                          &lt;th&gt;#springMessage("label.firstName")&lt;/th&gt;
                          &lt;th&gt;#springMessage("label.lastName")&lt;/th&gt;
                          &lt;th&gt;#springMessage("label.salary")&lt;/th&gt;
                          &lt;th&gt;#springMessage("label.birthdate")&lt;/th&gt;
                          &lt;th&gt;#springMessage("label.active")&lt;/th&gt;                          
                          &lt;tr&gt;
                              #foreach($empl in $editDepartament.depart_Employeers)
                                  &lt;tr&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].id"             'readonly="true"')&lt;/td&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].firstName"      'readonly="true"') &lt;/td&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].lastName"       'readonly="true"')&lt;/td&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].salary"         'readonly="true"')&lt;/td&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].birthday"       'readonly="true"')&lt;/td&gt;
                                  &lt;td&gt;#springFormInput("editDepartament.depart_Employeers[$velocityCount].active"         'readonly="true"')&lt;/td&gt;
                                  &lt;td&gt;&lt;a href="deleteEmployee/${empl.id}"&gt;#springMessage("label.delete")&lt;/a&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                              #end
                          &lt;/tr&gt;
                      &lt;/table&gt;
                 #end
          &lt;/form&gt;
  </code></pre>
  
  <p>Exception occurs after changing the title:</p>
  
  <pre><code>HTTP Status 500 - 
  
  --------------------------------------------------------------------------------
  
  type Exception report
  
  message 
  
  description The server encountered an internal error () that prevented it from fulfilling this request.
  
  exception 
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.employeers.domain.Employee; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.employeers.domain.Employee
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:681)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  
  
  root cause 
  
  org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.employeers.domain.Employee; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.employeers.domain.Employee
      org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:654)
      org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      $Proxy723.editDepartament(Unknown Source)
      com.mycompany.employeers.web.EmployeesController.updateDepartament(EmployeesController.java:204)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  
  
  root cause 
  
  org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.employeers.domain.Employee
      org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
      org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
      org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
      org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:755)
      org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1143)
      org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:39)
      org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
      org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
      org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
      org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      $Proxy723.editDepartament(Unknown Source)
      com.mycompany.employeers.web.EmployeesController.updateDepartament(EmployeesController.java:204)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  </code></pre>
  
  <p>And responsible for this view part of controller:</p>
  
  <pre><code>@RequestMapping(value="/updateDepartament", method= RequestMethod.POST)
      public String updateDepartament(@ModelAttribute("editDepartament")Departament dep, BindingResult result){
          departamentValidator.validate(dep, result);
          if(result.hasErrors()){
              return "editDepartament";
          }
          service.editDepartament(dep);
          return "redirect:/listDepartaments";
      }
  </code></pre>
  
  <p>Maybe someone knows how to solve this and can explain me?</p>