Please link me if same question has been answered earlier.Here is details of my problem.
I have a ShoppingCart object in database with following structure
Code:
ShoppingCart{
Set<ShoppingCartItem> lineItems
}
ShoppingCartItem{
Set<ShoppingCartAttributeItem> attributes
}
ShoppingCartAttributeItem{
// attributes
}
All above entities are DB backed entries in my Hibernate application.I need to merge 2 different instances of `ShoppingCart` at given conditions
1. User added some products to his cart.
2. After Adding product , user decided to login to system
There are cases when user has already a `ShoppingCart`, so moment he logged in to system . I need to merge his `ShoppingCart` with Current Session cart.
I can fetch both `ShoppingCart` from the DB
1. Fetch Cart associated with the current logged in user.
2. Fetch `ShoppingCart` associated with user before login
In Short, I need to merge `lineItems` of both the ShoppingCart.I am not sure how best I can do this?
Is there any efficient way to merge those `lineItems` or I need to create them one by one.?