users@glassfish.java.net

Re: JPA: how to alter relation without fetching entire entities?

From: <glassfish_at_javadesktop.org>
Date: Mon, 21 May 2007 14:51:34 PDT

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 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