title: JPA saving primary and foreign key together
body: <p>I have two Entities <code>DealEntity</code> and <code>DealTypeEntity</code>
  and they are related as-
  </p>
  
  <pre><code>@Entity
  class DealEntity{
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "DEAL_TYPE_ID")
    private DealTypeEntity dealTypeEntity;
  }
  </code></pre>
  
  <p>I am trying to save by creating instance of DealEntity which contains DealTypeEntity ref.</p>
  
  <p>I am using JPA and it giving me exception in <code>entityManager.persist(entity)</code></p>
  
  <pre><code>     Oct 17, 2013 3:36:34 PM org.apache.catalina.core.StandardWrapperValve invoke
       SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path             [/Travel-Portal] threw exception [Request processing failed; nested exception is          org.springframework.dao.InvalidDataAccessApiUsageException:org.hibernate.TransientPropertyV alueException: object references an unsaved transient instance - save the transient  instance before flushing: training.impetus.tp.model.DealEntity.dealTypeEntity -&gt;  training.impetus.tp.model.DealTypeEntity; nested exception is  java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object  references an unsaved transient instance - save the transient instance before flushing:  training.impetus.tp.model.DealEntity.dealTypeEntity -&gt;  training.impetus.tp.model.DealTypeEntity] with root cause
   org.hibernate.TransientPropertyValueException: object references an unsaved transient i nstance - save the transient instance before flushing:  training.impetus.tp.model.DealEntity.dealTypeEntity -&gt;  training.impetus.tp.model.DealTypeEntity
      at org.hibernate.engine.spi.CascadingAction$8.noCascade(CascadingAction.java:380)
      at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:176)
      at o rg.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEv entListener.java:160)
      at o  rg.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlus hingEventListener.java:151)
      at o    rg.hiborg.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:151)
      at org.hib
  </code></pre>