Reputation: 327
I have run into a EclipseLink issue with multiple queries running against the DB instead of a single query. I found the below SO threads which provides @BatchFetch annotation solution to help run as one master query
How to do join fetching instead of select fectching with EclipseLink?
How to define the EclipseLink annotation for the following?
But I am using EclipseLink 1.2 and the above annotation's classes are only supported by EclipseLink 2+. Appreciate if you could please help with an alternate solution for 1.2. I tried migrating the entire project to EclipseLink 2 but am running into mapping issues which I have no patience to fix right now.
I am using EclipseLink's JPA
Upvotes: 1
Views: 562
Reputation: 18379
The @BatchFetch annotation just set the mapping to use batch reading. You can do this in EclipseLink 1.2 using a DescriptorCustomizer and using the ForeignReferenceMapping API.
Upvotes: 1
Reputation: 30248
One way is to use a query hint, for example:
query.setHint(QueryHints.BATCH, "c.sourceTable");
In this case the sourceTable
relation for all c
's will be loaded with a single query, not one per c
.
Upvotes: 0