title: Entity Object Not Getting Persisted: New object was found through a relationship that was not marked
body: <p>I am trying to persist the following entity:</p>
  
  <pre><code>public class CommentEntity {
  
  @Id
  
  @ManyToOne(optional=false,cascade=CascadeType.REFRESH, targetEntity=UserEntity.class)
  @JoinColumn(name="USERID",referencedColumnName="USERID")
  private UserEntity userEntity;
  
  @ManyToOne(optional=false,cascade=CascadeType.REFRESH, targetEntity=PostEntity.class)
  @JoinColumn(name="POSTID",referencedColumnName="POSTID")
  private PostEntity postEntity;
  
  }
  </code></pre>
  
  <p>But the error comes out:</p>
  
  <p>During synchronization a new object was found through a relationship that was not marked cascade PERSIST: entity.PostEntity@16afec.</p>
  
  <p>when I try to persist PostEntity, it is persisted. No such exception is thrown:</p>
  
  <pre><code>public class PostEntity {
  
  @ManyToOne(optional = false, cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, targetEntity = UserEntity.class)
  @JoinColumn(name = "USERID", referencedColumnName = "USERID")
  private UserEntity userEntity;
  
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "postEntity", fetch = FetchType.LAZY)
  private List&lt;CommentEntity&gt; commentEntityList;
  }
  </code></pre>
  
  <p>Why it is happening? UserEntity is:</p>
  
  <pre><code>public class UserEntity {
  
  @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "userEntity")
  private List&lt;PostEntity&gt; postEntityList;
  
  @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "userEntity")
  private List&lt;CommentEntity&gt; commentEntityList;
  }
  </code></pre>
  
  <p>I am persisting commentEntity using the code:</p>
  
  <pre><code>entityManagerFactory = Persistence
                      .createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
              entityManager = entityManagerFactory.createEntityManager();
              entityTransaction = entityManager.getTransaction();
              entityTransaction.begin();
              entityManager.persist(commentEntity);
              entityTransaction.commit();
              entityManager.close();
  </code></pre>
  
  <p>I am not able to understand what can be the cause? And then why PostEntity is getting persisted in the same situation?</p>
  
  <p>I am using EclipseLink</p>