• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning generated ID's in Client VO's  RSS feed

 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a Page value object, which consists of several Samples value objects (one to many relationship).

When I try to save a fresh Page (along with one or more samples) here's the approach I follow:
1. Assign temporary ID to the page and each of its samples.
2. Convert the client-value object to its corresponding model value object.
3. Set the relationship within the value objects.
4. Invoke save on the Page, which will also save all the samples within.

So far things are working fine; the save operation functions smoothly and the inserts occur as expected.

Now, I need to assign the newly generated ID's for the page and the samples in the client-side value objects.

The problem here is that since the entire insert (for the page and all its samples) occurs at a go, I am at a loss to keep track as to which of the newly generated ID goes where. The temporary ID's seem to lose their significance given that I am not going and saving each sample individually.

Had I been saving each of the samples in, say, a for-loop it would have been easy for me to map the temporary Id with the corresponding newly-generated ID. But wouldn't this be bad design?

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