-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Efficient way to merge two DB backed entities in Hibernate
PostPosted: Mon Dec 23, 2013 1:54 pm 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
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.?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.