1

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

Community
  • 1
  • 1
AKSM
  • 327
  • 7
  • 20

2 Answers2

1

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.

James
  • 17,965
  • 11
  • 91
  • 146
  • In addition to QueryHint BATCH, I set the join columns to FETCH LAZY and also used Foreign Reference API's @JoinFetch(JoinFetchType.OUTER). We are not using any pagination, getting back the correct results – AKSM Nov 08 '11 at 15:32
0

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.

unbeli
  • 29,501
  • 5
  • 55
  • 57
  • @unbelli : thx for the response, I tried both @QueryHint(name = QueryHints.BATCH, value = "c.sourceTable") and query.setHint(QueryHints.BATCH, "c.sourceTable") before posting here. Observe multiple queries running against the DB for sourceTable join. It is like I've hit a brick-wall here – AKSM Nov 08 '11 at 13:43
  • well, post some code and we can fix it. query.setHint works for me. – unbeli Nov 08 '11 at 13:48