if a Seller wants to sell an Item, it comes to a page & try to add Item
process finds that this is not registered seller, and provide seller a page to fill seller detail.
- Seller (object) Entity is created, but not attached
Seller fills detail of Item
- Item Enity (object) is created
Item has relationship with seller, so while creating Item one step is
process finds the seller
- Seller seller = em.find(Seller.class, sellerId);
case 2 is from EJB 3 in Action page 315, case 1. is my asumption (if seller does not exist, and wants to add item).
EM will check if item PK does not exist, it will add Item to db in this case, but I am not sure how EntityManager will treat to Seller entity in Case 2. & Case 1.
Joined: Feb 24, 2009
or may be case 1 is not good enough
it must have
Seller seller = new Seller();
- em.persist(seller); //if seller id is IDENTITY (auto generated) flush should needed to manage Seller
(now this Case 1 is also like Case 2 for EnetityManager).