2007/5/21, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> If you have the addressId, why not simply remove it like you do in steps 3 and 4? Why fetch the entire list at all?
If I remove that address using em.remove(addressToRemove) then it will
still remain as an object in collection returned by
person.getAddresses() (assuming that entity is hold by L2 cache).
That will eventually result in some exception, when TopLink finds out,
there is address somewhere in L2 cache that does not exist anymore.
>
> If it's going through a join table, then there may be an issue, but you have it listed as a OneToMany, but you don't have a join table. In this simple case, simply removing the address directly should work fine.
>
> Now, updating the join table is much more of a trick, as the join table entries themselves aren't promoted to the model tier at all, and thus really have no exposure outside of the contain object. And you can't easily just call native sql to do the job without flushing out the entire 2nd tier cache, which in turn may be more expensive than loading the relationship itself.
>
> Someone else would have to chime in regarding the affects on the 2nd tier cache if you went after the DB directly (DELETE FROM JOINTABLE WHERE personid = xxx and addressid = yyy).
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=218218
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>