|
By the way, I forgot to mention another workaround for the cases in which you need two or more fields from the joined entity... Although it requires some work from the developer. When the query turns very complex, I divide it in 2 queries. One without the OUTER LEFT JOIN that retrieves the main results, and another one that obtains the data that had been obtained using an OUTER LEFT JOIN. So basically it consists in converting the JOIN in a separate query.
Then, I create a java.util.HashMap with the results of the second query, using the primary keys of such results as keys of the map. Finally I loop over the results of the first query and lookup for the corresponding registries in the HashMap, using the method HashMap::get ().
Obviously it's slower than a single query. But if you want to keep your application fully portable (without native SQL), it's a good solution. At least it has worked for me for all these years .
|