title: how to mapping an OneToMany relation with Weak Entity in Hibernate
body: <p>I need to map a OneToMany relationship in hibernate, with the JPA annotations, in which is involved a weak entity.<br>
  For example<br>
  Table orders:  </p>
  
  <pre><code>CREATE TABLE orders(
  idorder serial NOT NULL,
  note varchar(30),
  CONSTRAINT orders_pkey PRIMARY KEY (idorder)
  )
  </code></pre>
  
  <p>Table OrderItems:</p>
  
  <pre><code>CREATE TABLE orderitems(
    idorder integer NOT NULL,
    iditem serial NOT NULL,
    qnt integer,
    CONSTRAINT orderitems_pk PRIMARY KEY (idorder, iditem),
    CONSTRAINT fk_orderitems FOREIGN KEY (idorder)
        REFERENCES orders (idorder) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION
  )
  </code></pre>
  
  <p>Within my class "Orders" I have realized the method getOrderItem() in this way:</p>
  
  <pre><code>// i need cascadeType.All here
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "order")
  public Set&lt;OrderItem&gt; getOrderItems() {
      return items;
  }
  </code></pre>
  
  <p>now,
  not being able to know the identifier that will be assigned to a new order
  prior to insertion, such as Annotations can I use within the class OrderItem in order to submit automatically (in cascade mode) the correct idOrder?<br>
  my goal is to get a situation like this.</p>
  
  <pre><code>Order myOrder = new Order();
  //      myOrder.setId(1) not necessary
  myOrder.setNote("orderNote");
  
  OrderItem firstItem = new OrderItem();  
  // firstItem.setIdOrder()       no need to specify idorder
  // firstItem.setId(12);
  firstItem.setName("firstItem");
  firstItem.setQnt(2);
  
  OrderItem secondItem = new OrderItem();
  // secondItem.setId(13);
  secondItem.setName("secondItem");
  secondItem.setQnt(4);
  
  Set&lt;OrderItem&gt; items = new HashSet&lt;OrderItem&gt;();
  items.add(firstItem);
  items.add(secondItem);
  
  myOrder.setItems(items);
  
  OrderDAO dao = new OrderDAO();
  dao.save(myOrder);  // i want inser all items in cascade with the idOder assigned to "myOrder"
  </code></pre>