title: Hibernate @ManyToOne annotation creating only the child referencing existing parent table
body: <p>I am currently working on a project in which i have to use manytoone relationship. I want to retrieve the parent from an existing table in the DB and map to a new child object. But each time i do this it fails and instead tries to create the parent over again. here are the variable declarations:</p>
  
  <pre><code>@Entity @Table (name= "children")
  public class Child implements Serializable{
  @ManyToOne (fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
  @JoinColumn (name = "parent_id",referencedColumnName = "id")
  private Parent parent;
  }
  </code></pre>
  
  <p>each time i create a new child record it tries to create a new parent with the data of an existing parent i pulled from the database leading to the this error:</p>
  
  <pre><code>duplicate key value violates unique constraint "parents_parent_name_key"
  Detail: Key (parent_name)=(Jimmy) already exists.
  
  Batch entry 0 insert into parents(parent_name, id) values ('Jimmy', '13')     was
  aborted.  Call getNextException to see the cause.
  </code></pre>
  
  <p>then if i try to redo this i get a different error:</p>
  
  <pre><code>org.hibernate.PersistentObjectException: detached entity passed to persist:
  com.house.entity.Parent
  </code></pre>
  
  <p>Thank yiu</p>