title: org.hibernate.TransientObjectException: object references an unsaved transient instance
body: <p>Here I am trying to update <code>SupplierPaidDetail</code> including data in(<code>supplierPaidOnlines</code>,<code>supplierPaidCashes</code>,<code>supplierPaidChecks</code>)  following are my code but this is showing exception.</p>
  <p><strong>JSP Page:</strong></p>
  <pre><code>&lt;s:form action=&quot;UpdatedPaid&quot; method=&quot;post&quot;&gt;  
      &lt;s:if test=&quot;paidList.size&gt;0&quot;&gt; 
          &lt;s:iterator value=&quot;paidList&quot; var=&quot;pdlst&quot;&gt;
              &lt;div class=&quot;box&quot;&gt;
                  &lt;span class=&quot;label&quot;&gt;Payment Date&lt;/span&gt;
                  &lt;span class=&quot;ib&quot;&gt;
                      &lt;s:hidden name=&quot;id&quot; id=&quot;paidId&quot; value=&quot;%{paidId}&quot;/&gt;
                      &lt;s:hidden name=&quot;supplierPaymentDetails.id&quot; value=&quot;%{supplierPaymentId}&quot;/&gt;
                      &lt;s:textfield name=&quot;paymentDate&quot; id=&quot;paymentDate&quot; value=&quot;%{paymentDate}&quot;/&gt;
                  &lt;/span&gt;
              &lt;/div&gt;
              &lt;div class=&quot;box&quot;&gt;
                  &lt;span class=&quot;label&quot;&gt;Payment Mode&lt;/span&gt;
                  &lt;span class=&quot;ib&quot;&gt;
                      &lt;s:textfield name=&quot;paymentMode&quot; id=&quot;payment_mode&quot; readonly=&quot;true&quot; value=&quot;%{payment_mode}&quot;/&gt;
                  &lt;/span&gt;
              &lt;/div&gt;
              &lt;s:if test=&quot;cashActionList.size&gt;0&quot;&gt; 
                  &lt;s:iterator value=&quot;cashActionList&quot; status=&quot;rowstatus&quot;&gt;
                      &lt;div class=&quot;box&quot;&gt;
                          &lt;span class=&quot;label&quot;&gt;Amount&lt;/span&gt;
                          &lt;span class=&quot;ib&quot;&gt; 
                              &lt;s:textfield name=&quot;supplierPaidCashes[%{#rowstatus.index}].amount&quot; id=&quot;amount&quot; value=&quot;%{amount}&quot;/&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;box&quot;&gt;
                          &lt;span class=&quot;label&quot;&gt;TO Person&lt;/span&gt;
                          &lt;span class=&quot;ib&quot;&gt;
                              &lt;s:hidden name=&quot;supplierPaidCashes[%{#rowstatus.index}].id&quot; id=&quot;id&quot; value=&quot;%{id}&quot;/&gt;
                              &lt;s:textfield name=&quot;supplierPaidCashes[%{#rowstatus.index}].toPerson&quot; id=&quot;toPerson&quot; value=&quot;%{toPerson}&quot;/&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;box&quot;&gt;
                          &lt;span class=&quot;label&quot;&gt;Designation&lt;/span&gt;
                          &lt;span class=&quot;ib&quot;&gt;
                              &lt;s:textfield name=&quot;supplierPaidCashes[%{#rowstatus.index}].Designation&quot; id=&quot;Designation&quot; value=&quot;%{Designation}&quot;/&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;box&quot;&gt;
                          &lt;span class=&quot;label&quot;&gt;Receipt No&lt;/span&gt;
                          &lt;span class=&quot;ib&quot;&gt;
                              &lt;s:textfield name=&quot;supplierPaidCashes[%{#rowstatus.index}].receiptNo&quot; id=&quot;receiptNo&quot; value=&quot;%{reciptNo}&quot;/&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/s:iterator&gt;
              &lt;/s:if&gt;
          &lt;/s:iterator&gt;
      &lt;/s:if&gt;
  &lt;/s:form&gt;
  </code></pre>
  <p><strong>In Action:</strong></p>
  <pre><code>public class hbmCashAction extends ActionSupport implements ModelDriven&lt;SupplierPaidDetails&gt; {
  
      SupplierPaidDetails spa = new SupplierPaidDetails();
  
      public String update() {
          System.out.println(&quot;--------&quot;);
  
          System.out.println(&quot;id&quot; + spa.getId() + &quot; &quot; + spa.getPaymentDate());
          SupplierPaymentDetails spdd = new SupplierPaymentDetails();
          spa.setSupplierPaymentDetails(spdd);
          List&lt;SupplierPaidCash&gt; aca = spa.getSupplierPaidCashes();
          for (SupplierPaidCash ss : aca) {
              System.out.println(&quot;Cash Details&quot;);
              ss.setSupplierPaidDetails(spa);
              System.out.println(ss.getId() + &quot; &quot; + ss.getAmount() + &quot; &quot; + ss.getToPerson());
          }
          List&lt;SupplierPaidCheck&gt; ax = spa.getSupplierPaidChecks();
          for (SupplierPaidCheck ss : ax) {
              System.out.println(&quot;Check Details&quot;);
  
              ss.setSupplierPaidDetails(spa);
              System.out.println(ss.getId() + &quot; &quot; + ss.getPaidToAccNo() + &quot; &quot; + ss.getPayableAt());
          }
          List&lt;SupplierPaidOnline&gt; onl = spa.getSupplierPaidOnlines();
          for (SupplierPaidOnline ss : onl) {
              System.out.println(&quot;Online Details&quot;);
              ss.setSupplierPaidDetails(spa);
              System.out.println(ss.getId() + &quot; &quot; + ss.getPaidToAccNo() + &quot; &quot; + ss.getPayRefNo());
          }
          System.out.println(&quot;--------&quot;);
          CashDao co = new CashDao();
          co.update(spa);
          return SUCCESS;
      }
    }
  </code></pre>
  <p><strong>DAO:</strong></p>
  <pre><code>public class CashDao {
  
      public void update(SupplierPaidDetails spd) {
  
          Session session = HibernateUtil.getSessionFactory().openSession();
          session.beginTransaction();
          try {
              session.update(spd);
          } catch (HibernateException e) {
              System.out.println(&quot;Exception  &quot; + e);
              session.getTransaction().rollback();
          }
          session.getTransaction().commit();
  
      }
    }
  </code></pre>
  <p><strong><code>SupplierPaidDetalis</code>:</strong></p>
  <pre><code>public class SupplierPaidDetails implements java.io.Serializable {
  
      private Long id;
      private SupplierPaymentDetails supplierPaymentDetails;
      private String paymentMode;
      private Date paymentDate;
      private Date addDate;
      private String status;
      private List&lt;SupplierPaidOnline&gt; supplierPaidOnlines = new ArrayList();
      private List&lt;SupplierPaidCash&gt; supplierPaidCashes = new ArrayList();
      private List&lt;SupplierPaidCheck&gt; supplierPaidChecks = new ArrayList();
   /getter and setter
   }
  </code></pre>
  <p><strong><code>supplierPaidDetails.hbm.xml</code>:</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;
  &quot;http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd&quot;&gt;
  &lt;!-- Generated May 10, 2014 11:18:04 PM by Hibernate Tools 3.6.0 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name=&quot;iland.hbm.SupplierPaidDetails&quot; table=&quot;supplier_paid_details&quot; catalog=&quot;retail_shop&quot; dynamic-update=&quot;true&quot;&gt;
          &lt;id name=&quot;id&quot; type=&quot;java.lang.Long&quot;&gt;
              &lt;column name=&quot;id&quot; /&gt;
              &lt;generator class=&quot;identity&quot; /&gt;
          &lt;/id&gt;
          &lt;many-to-one name=&quot;supplierPaymentDetails&quot; class=&quot;iland.hbm.SupplierPaymentDetails&quot; fetch=&quot;select&quot;&gt;
              &lt;column name=&quot;supp_payment_id&quot; not-null=&quot;true&quot; /&gt;
          &lt;/many-to-one&gt;
          &lt;property name=&quot;paymentMode&quot; type=&quot;string&quot;&gt;
              &lt;column name=&quot;payment_mode&quot; length=&quot;20&quot; /&gt;
          &lt;/property&gt;
          &lt;property name=&quot;paymentDate&quot; type=&quot;date&quot;&gt;
              &lt;column name=&quot;payment_date&quot; length=&quot;10&quot; /&gt;
          &lt;/property&gt;
          &lt;property name=&quot;addDate&quot; type=&quot;timestamp&quot;&gt;
              &lt;column name=&quot;add_date&quot; length=&quot;19&quot; default=&quot;0&quot; /&gt;
          &lt;/property&gt;
          &lt;property name=&quot;status&quot; type=&quot;string&quot;&gt;
              &lt;column name=&quot;status&quot; length=&quot;20&quot; /&gt;
          &lt;/property&gt;
          &lt;list name=&quot;supplierPaidOnlines&quot; table=&quot;supplier_paid_online&quot; inverse=&quot;true&quot; lazy=&quot;true&quot; fetch=&quot;select&quot; cascade=&quot;all&quot; &gt;
              &lt;key column=&quot;spd_id&quot;  /&gt;
              &lt;list-index column=&quot;id&quot; /&gt;
              &lt;one-to-many class=&quot;iland.hbm.SupplierPaidOnline&quot; /&gt;
          &lt;/list&gt;
          &lt;list name=&quot;supplierPaidCashes&quot; table=&quot;supplier_paid_cash&quot; inverse=&quot;true&quot; lazy=&quot;true&quot; fetch=&quot;select&quot; cascade=&quot;all&quot;&gt;
              &lt;key column=&quot;spd_id&quot;  /&gt;
              &lt;list-index column=&quot;id&quot; /&gt;
              &lt;one-to-many class=&quot;iland.hbm.SupplierPaidCash&quot; /&gt;
          &lt;/list&gt;
          &lt;list name=&quot;supplierPaidChecks&quot; table=&quot;supplier_paid_check&quot; inverse=&quot;true&quot; lazy=&quot;true&quot; fetch=&quot;select&quot; cascade=&quot;all&quot;&gt;
              &lt;key column=&quot;spd_id&quot;  /&gt;
              &lt;list-index column=&quot;id&quot; /&gt;
              &lt;one-to-many class=&quot;iland.hbm.SupplierPaidCheck&quot; /&gt;
          &lt;/list&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  <p><strong>Exceptions :</strong></p>
  <pre><code>SEVERE: Exception occurred during processing request: object references an unsaved transient instance - save the transient instance before flushing: iland.hbm.SupplierPaymentDetails
  org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: iland.hbm.SupplierPaymentDetails
      at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
      at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
      at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:121)
      at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2559)
      at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2495)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2822)
      at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
      at iland.payment.CashDao.update(CashDao.java:57)
      at iland.payment.hbmCashAction.update(hbmCashAction.java:64)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
      at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
      at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
      at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  <p>How to resolve above exceptions?</p>