title: JPA insert object if not exists, do nothing if exists
body: <pre><code>@Entity
  @Table(name="PROPERTY_VALUES")
  public class PropertyValuesData extends AbstractData {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="VAL_ID")
      private Long id;
  
      @OneToOne(fetch = FetchType.EAGER, cascade=  {CascadeType.PERSIST} )
      @JoinColumn(name = "VAL_PROP_ID")
      private PropertyData property;
  
  }
  </code></pre>
  
  <p>Persist object:</p>
  
  <pre><code>  public void createItem(TYPE item){
              try{
                  em=EMFactory.createEntityManager();
                  em.getTransaction().begin();
                  em.persist(item);
                  em.getTransaction().commit();
              }catch(Exception e){
                  logger.error("Error while createItem", e);
                  System.err.println(e.getMessage());
              }finally {
                  if(em!=null)
                      em.close();
              }
          }
  </code></pre>
  
  <p>I have 2 situation:
  1) I create new object <code>PropertyValuesData</code>, which contain existing property (with id) -> then I want to ONLY add new <code>PropertyValuesData</code>
  2)  I create new object <code>PropertyValuesData</code>, with new property -> then I want to insert also new <code>PropertyData</code>.</p>
  
  <p>If I add <code>CascadeType.PERSIST</code>, then I can save new property, but for existing property it try insert it again. What should I do to avoid insert again the same property?</p>