users@glassfish.java.net

Re: Basic JPA Question

From: <glassfish_at_javadesktop.org>
Date: Wed, 17 Oct 2007 19:02:11 PDT

>
> For example, let's say Server "A" has a list of CPU's containing CPU's with ID's "1" and "2". Another Server, "B", also has a list of CPU's which also contains CPU's with ID's "1" and "2".

Do you mean that a CPU "1" in Server "A" is not the same as in Server "B"?

> ----
>
> As far as merging goes, from what I have seen, let's say you persist Server "A", above The child entities, CPU's with ID's "1" and "2" are also persisted to the database. If I want to update Server "A", but now it only has 1 single child CPU, with ID "3", if I did a simple merge, I would have CPU "1", "2", and "3" in the database instead of just having CPU "3" like I intended.
>

You can do em.find(<Server "A">), then compare the collections of CPUs and adjust accordingly. It's not pretty but better than remove/insert solution.

Regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

http://forums.java.net/jive/thread.jspa?messageID=240818