title: object references an unsaved transient instance : save the transient instance before flushing
body: <p>I have two entities: PlayerProfileEntity &amp; UserInfoEntity
  I have a join on userInfoEntity &amp; PlaterProfileEntity and saving my record in database like this:</p>
  
  <pre><code>Session session = sessionFactory.openSession();
  Transaction tr = session.beginTransaction();
  Criteria crit = session.createCriteria(PlayerProfileEntity.class);
  player.setUserId(new UserInfoEntity());
  player.getUserId().setAddress(user.getUserId().getAddress());
  session.save(player);
  tr.commit();
  </code></pre>
  
  <p>I used this assosiation in my PlayerProfileEntity class</p>
  
  <pre><code>@ManyToOne (fetch = FetchType.LAZY)
  @Cascade({CascadeType.REFRESH})
  @JoinColumn(name="userid")
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>org.hibernate.TransientObjectException: object references an unsaved transient instance - save     the transient instance before flushing: com.shared.entity.UserInfoEntity
  </code></pre>
  
  <p>Note : If i use CascadeType.All, i get this error:</p>
  
  <pre><code>Cannot add or update a child row: a foreign key constraint fails
  </code></pre>
  
  <p>Any idea how can i solve this</p>
  
  <p>Thanks </p>