Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Deep Clone of Entities

 
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Do you want ants? Because that's how you get ants. And a tiny ads:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic