users@glassfish.java.net

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

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Wed, 23 May 2007 00:37:20 +0200

2007/5/22, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> You can prefetch Persons for those Addresses that you need to delete if you do WHERE AddressId IN(x, y, z, ...). Then you won't go to the database for any more selects, and if a provider supports batching, all the updates will not take too long.

What do you mean by "WHERE Addrss in (x,y,z...)"
If I have few hundreds or few thousands entities to alter, how am I
suppose to build such a query? Using StringBuilder which will be few
thousands characters long? Is it going to go through entity manager?
If "Person" entity is big, is it going to fit in memory?
That will certainly not work.


>
> But yes, there is no easy way to do it in a single step.

It is actually very common task one might need to do in any database
application and it is not going to work using JPA.

All this JPA works only in tutorials, not in real apps. The problem is
that I've trusted JPA already and now I have huge problems and
performance issues :/

My DTO -> Entity methods of service beans are even 100 lines long just
to map quite simple FirmDTO to be "translated" and merged into "Firm"
entity... (do you want me to paste such a method here?) I am hopeless.