• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deep Clone of Entities  RSS feed

 
Ranch Hand
Posts: 149
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I need to get a clone of a fairly deep object tree.
All objects are entities and I need to set the primary keys to null.

The root object:


dependent class



When I call


grundentscheidungClone contains the whole object tree with all dependencies, but
the Tatbestand objects have their primary keys.
When I use the debugger I see that Tatbestand.clone() is never called.

Is my code faulty? I would like to avoid to write a large method which sets all primary keys on the object tree to null.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Markus Schmider wrote:When I use the debugger I see that Tatbestand.clone() is never called.
Is my code faulty? I would like to avoid to write a large method which sets all primary keys on the object tree to null.

Well, one possible problem is that List isn't Cloneable. Most implementations of List are; but I'm not sure that that's sufficient (this looks rather like a Hibernate declaration, and I honestly don't know what implementation it uses).

I'm also worried about the "set all primary keys on the object tree to null" bit. It sounds like a recipe for disaster to me, unless you have some mechanism for resetting them ALL to something else before you actually do anything with this "clone".

My suggestion: Why don't you back up and explain what you're trying to do? All we know so far is HOW you want to do it, and it's plainly not working. Deep cloning is NOT simple; and to be honest, I've never tried it with a database object Map.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!