B) The problem I had to make forms for different elements. I had to fill the form (name, currency...), view it and modify it.
However, while modifying the form, I had to be able to perform a classic undo (using a hit on my cancel button) and then retrieve the state of my country as it was before I began doing updates...
In the first case the entity is saved, in the latter case it is updated.
So let's examine the three possible cases and what the different methods do: I hope this blog gives you some pointers on how to save entities and how to work with detached entities. JDO 2.x uses the same method, Persistence Peristent(Object) for both persisting new objects and merging detached objects.
We'll get back to detached entities when we discuss Data Transfer Objects in a later blog. There is no distinction between persisting and attaching.
- Easy to implement when you have "hello world" sample with 3 or 4 entities living quite independently from each other.
But it's a pity to maintain when you have dozens of entities all of them being part or collection of the other...
To speed up the development we successfully use Hyper JAXB 3 ( which generates 90% of the code, though still need to handcraft some JPA annotations anyway. I see that Jeanne Boyarsky has already answered your question over at Code Ranch.