title: Hibernate, insert or update without select
body: <p>I have a products objects which belongs to certain categories i.e. classical many to one relationship.</p>
  
  <pre><code>@Entity
  public class Product{
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      Long id;
  
      String name;
      Double price;
      @ManyToOne(fetch = FetchType.LAZY)
      Category category;
  ...
  }
  
  @Entity
  public class Category implements Identifiable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      private String name;
  ...
  }
  </code></pre>
  
  <p>I want to insert and update products without preselecting categories. Like this:</p>
  
  <pre><code>Product product = dao.get(productId);
  Category category = dao.get(categoryId);
  product.setCategory(category);
  dao.update(product);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Product product = new Product(somename);
  Category category = dao.get(categoryId);
  product.setCategory(category);
  dao.insert(product);
  </code></pre>
  
  <p>Is it possible to update and insert without category selecting? I don't want to use HQL or direct queries for that.</p>