-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to Copy/Duplicate child elements
PostPosted: Thu Feb 15, 2007 6:36 pm 
Newbie

Joined: Thu Feb 15, 2007 12:48 pm
Posts: 11
Hi,
Is it possible to copy child elements from one parent to another. I tried something like the code below but I get an NonUniqueException: a different object with same identifier Value.

BTW, I am new to Hibernate and .Net, so please excuse my bad code style.

Thanks,
Javid

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
Template old = (Template) Db.Session.Get(typeof(Template), int.Parse(oldTemplateID));

Template newtemplate = new Template();
                    newtemplate.TemplateName = txtTemplateName.Text;
                   
                    foreach (TemplateValue value in old.TemplateValues)
                        newtemplate.AddTemplateValue(new TemplateValue(value));
                    Db.Save(newtemplate);

public void AddTemplateValue(TemplateValue value)
        {
            if (TemplateValues.Contains(value))
                return;
            value.Parent = this;
            TemplateValues.Add(value);
            Db.Session.Save(value);
        }

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 2:02 am 
Newbie

Joined: Wed Feb 14, 2007 6:24 pm
Posts: 5
I think you may need to deeply copy your objects, i.e. construct a new TemplateValue object for each item in the source collection and add the newly constructed copies to the destination collection.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.