-->
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.  [ 4 posts ] 
Author Message
 Post subject: Duplicating a record
PostPosted: Sat May 10, 2008 3:13 am 
Beginner
Beginner

Joined: Wed Dec 06, 2006 6:24 am
Posts: 24
Location: Bangalore
Hi,

I have following Objects:

1) EventDb
2) ContactInfo
3) KeynoteInfo etc

there is parent child relationship from Event --> ContactInfo, KeynoteInfo.

Code:

public class EventDb  implements java.io.Serializable {


     private String genericEventId;
     private EventDb eventDb;
     private String eventName;
     private String eventYear;
     .......     
   
     private List<ContactInfo> contactInfos = new ArrayList<ContactInfo>(0);
   
   private List<KeynoteInfo> keynoteInfos = new ArrayList<KeynoteInfo>(0);

// other childs...

    public EventDb() {
    }

   // code......


public class ContactInfo  implements java.io.Serializable {


     private String contactId;
     private EventDb eventDb;   
     private String contactName;   
     private Character isDuplicated;
     .......

    public ContactInfo() {
    }

// remaining code..


same way KeynoteInfo POJO.

My requirement:

I need to duplicate the data of selected EventDb and its childs as a new record in the database.

please tell me how to do this duplicate operation.

thanks in advance.

_________________
Vinay N


Top
 Profile  
 
 Post subject: Duplicating a record
PostPosted: Sat May 10, 2008 7:22 pm 
Newbie

Joined: Sat May 10, 2008 6:13 pm
Posts: 1
i do not know if there is any better way...
once you have selected the object graph for the EventDB, set the primary key id to 0 on each of the objects in the graph and save(persist) it so that you will have a duplicate record. You need to make the set methods for the primary key id as public.


Top
 Profile  
 
 Post subject: Deep cloning
PostPosted: Sun May 11, 2008 8:24 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi,
I see that the child objects also have their own IDs, which means they are stored within their own table, correct?
What you need is a "deep cloning" procedure that can pick up any one of your entities and clone it with any relevant information in it.

Am I correct?
If so, I've done something similar in a recent project. There are several design solutions. A simple one:

Implement some 'clone' method in all your entities, that performs deep-cloning. You may create different variations, i.e. cloneForInsert, cloneForSelect, each clones a different set of properties.

I have some other more "exotic" ideas which I have used for very complex entity graphs, but the above is usually ok for most cases.


Top
 Profile  
 
 Post subject: Deep Cloning
PostPosted: Thu May 15, 2008 4:22 am 
Beginner
Beginner

Joined: Wed Dec 06, 2006 6:24 am
Posts: 24
Location: Bangalore
Hi sagimann,

I also got the same idea after going through few post in forum,
instead of cloning method i've tried using copy constructor, which is working fine.

Thanks sagimann & kcbhiber for your suggestions.

Regards
Vinay


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

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.