-->
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.  [ 6 posts ] 
Author Message
 Post subject: Navigating/Updating a Clone
PostPosted: Sun Jun 06, 2004 3:00 pm 
Newbie

Joined: Sun Jun 06, 2004 2:54 pm
Posts: 7
If I clone a (possibly detached) persistent object (actually, I would use a copy constructor since clone() is so badly flawed), can I later associate the clone with a hibernate session so that i can navigate/update the clone just like the original object? Or is the original object somehow special in a way that the clone cannot be?

Thanks!


Top
 Profile  
 
 Post subject: clone() and fields
PostPosted: Sun Jun 06, 2004 7:19 pm 
Newbie

Joined: Sun Jun 06, 2004 2:54 pm
Posts: 7
Actually, come to think of it, cloning persistent objects just about /must/ work using a correct clone implementation because it will do field copies of any magically modified/generated fields. But is there some subtle way that using a cloned object like this could mess up Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 4:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No. Just be careful when using proxys.


Top
 Profile  
 
 Post subject: copy constructor
PostPosted: Mon Jun 07, 2004 12:16 pm 
Newbie

Joined: Sun Jun 06, 2004 2:54 pm
Posts: 7
okay, so clone() will work. but if i copy construct an object, is there any way to attach that non-persistent object to a hibernate session *as the original* (with the same identity and version)? if not, is this feature possible in some future hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, just do it using session.lock(object, LockMode.NONE)


Top
 Profile  
 
 Post subject: lazy proxies
PostPosted: Mon Jun 07, 2004 1:45 pm 
Newbie

Joined: Sun Jun 06, 2004 2:54 pm
Posts: 7
okay i think i see what you are saying now. the id and version must be ordinary attributes of the object that i can just copy manually, right?

the trickiness must be all about lazy proxies and navigation...

so what happens if i have Library object that has a lazy collection of books that is being navigated (maybe there are only 100 out of 10000000) books loaded. i want to create a copy of the Library object using an ordinary copy constructor. but i want to be able to navigate the copy just like the original. how would i accomplish this? obviously session.lock can't do this magic because the object already exists and it is non-bytecode-instrumented. wouldn't i need something like session.clone(object)? or is there some workaround to get the copy to have the same proxies as the original?


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