title: Hibernate does not save my newly created objects
body: <p>I have a pretty simple tables structure:
  table <strong>Products</strong> with <strong>product_id</strong> and <strong>name</strong> attributes.
  table <strong>Barcodes</strong> with <strong>product_id</strong> (foreign key to the Products table) and <strong>code</strong> attributes.</p>
  
  <p>In my code I create new instance of a Product object:</p>
  
  <pre><code>Product product = new Product();
  </code></pre>
  
  <p>and I save the product:</p>
  
  <pre><code>session.save(product);
  </code></pre>
  
  <p>Later I create new instance of a Barcode object:</p>
  
  <pre><code>Barcode barcode = new Barcode();
  </code></pre>
  
  <p>and associate the product with the barcode:</p>
  
  <pre><code>barcode.setProduct(product);
  </code></pre>
  
  <p>and try to save the barcode:</p>
  
  <pre><code>session.save(barcode);
  </code></pre>
  
  <p>and I'm getting:</p>
  
  <blockquote>
    <p>Exception in thread "main" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:</p>
  </blockquote>
  
  <p>Any ideas?</p>