title: How to set unique rows when persist in JPA?
body: <p>My question is: is there any way to set unique row for rows created by &quot;new&quot; keyword?
  I mean like this:</p>
  <pre><code>Product product = Product.builder()
              .eancode(&quot;EAN-1234&quot;)
              .externalId(&quot;123123&quot;)
              .producerPartNumber(&quot;123123&quot;)
              .name(&quot;VERY GOOD LAPTOP&quot;)
              .vendor(new Vendor(&quot;LENOVO&quot;, &quot;www.lenovo.com&quot;))
              .priceDetails(new PriceDetails(
                      new BigDecimal(&quot;19.99&quot;),
                      new BigDecimal(&quot;20.00&quot;),
                      new BigDecimal(&quot;21.00&quot;),
                      Currency.PLN))
              .build();
  </code></pre>
  <p>I want Vendor entity to be unique because now I've got something like this (when I multiply run this code):</p>
  <pre><code>id name    url
  1  LENOVO  lenovo.com
  2  LENOVO  lenovo.com
  </code></pre>
  <p>I just want it to check it first if that name exist yet. Should I use @EmbeddedId in some way?</p>
  <p>Edit: look now</p>
  <pre><code>@Override
      public Long save(Product item) {
          EntityManager em = getEntityManager();
          em.getTransaction().begin();
          
          //that line throws PersistentObjectException: detached entity passed to persis
          em.persist(item); //cascade is set as PERSIST so why isn't it work
          
          em.getTransaction().commit();
          em.close();
          return item.getId();
      }
  </code></pre>