-->
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 generate a new ID for an detached entity?
PostPosted: Tue May 31, 2005 7:50 am 
Newbie

Joined: Tue May 24, 2005 7:54 am
Posts: 4
Location: Beijing in China
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

If I have a detached object named "cat" with an identifier "1" and I want to import it to the database, so I can use session.replicate() to overwrite the existed row in the database with the same ID "1". But I have another requirement that I need to import the object like a new one, that means I must import the object cat with the same content except the identifier "1",
how can I generate the detached object cat's ID automatically,and how can I update the parent's ID stored in the cat's children, I need generate new ID for cat's children too, for the detached object cat is contains not only cat but also cat's children too, I must import all the objects like new ones.
Thank you in advance!
Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

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:


Top
 Profile  
 
 Post subject: Re: How to generate a new ID for an detached entity?
PostPosted: Tue May 31, 2005 9:14 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
baconshen wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

If I have a detached object named "cat" with an identifier "1" and I want to import it to the database, so I can use session.replicate() to overwrite the existed row in the database with the same ID "1". But I have another requirement that I need to import the object like a new one, that means I must import the object cat with the same content except the identifier "1",
how can I generate the detached object cat's ID automatically,and how can I update the parent's ID stored in the cat's children, I need generate new ID for cat's children too, for the detached object cat is contains not only cat but also cat's children too, I must import all the objects like new ones.
Thank you in advance!
Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

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:


Assuming you are not used generator=assigned as your IdGenerator, you should be able to assign null to your ID prior to calling session.save() with the detatched Cat and it should be persisted as a new object. You would need to do this for each of the kittens as well.


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.