users@glassfish.java.net

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

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Tue, 22 May 2007 13:35:33 +0200

> You can call addressToRemove.getPersons().clear() to clear the other side. There

No, I cant:
1) address does not know about person, so there is no getPersons()
2) even if address would have getPersons() collection, I still cannot
use that, because:
 2a) that would clear all persons from address, not the only one I want
 2b) even if I would like to remove every person from that address, I
would have to em.find each person that was in that collection and
search that address inside getAddresses() collection for EACH person..
that means huge, multimega extra massive amount of data that need to
be queried and downloaded from database, where in SQL there is only
one, tiny
"DELETE FROM >jointable< where X AND Y"
or
"UPDATE forExample:Address where forExample:person_id=X"

The only reasonable solution for that would be an option to clear
selected entity from L2cache, so I could update database and clear
from L2 only somehow related entities.

Right now, there is NO acceptable solution for altering entities
relationship, if one have to do it on large number of entities. If I
want to remove certain addresses from, lets say 30000 persons, there
might be 100 or 200k queries send to database.