Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] batch loading of single object reporting that query is not a single object

I have 2 Entities

  • Story, which has a 1-to-many ordered bidirectional relationship with
  • Scenario, which has an ElementCollection of tags (a List element collection)

I want to write a query that returns the Scenarios for a given Story ID, however, I want the ability to limit the number of results AND to batch/pre-load the Scenario tags.

When I run the following:

em.getTransaction().begin();
String jpql = "select sc from Story s JOIN s.scenarios sc WHERE s.id = :storyId order by index(sc) asc";
TypedQuery<Scenario> query = em.createQuery(jpql, Scenario.class);
query.setParameter("storyId", 2);
query.setFirstResult(0);
query.setMaxResults(15);
query.setHint(QueryHints.BATCH, "sc.tags");
query.setHint(QueryHints.BATCH_TYPE, "IN");
query.setHint(QueryHints.LOAD_GROUP_ATTRIBUTE, "tags");
List<Scenario> results = query.getResultList();
em.getTransaction().commit();

I get the following error:

Exception in thread "main" java.lang.IllegalArgumentException: Query select sc from Story s JOIN s.scenarios sc WHERE s.id = :storyId order by index(sc) asc, query hint eclipselink.batch is not valid for this type of query.

Which is because Eclipselink thinks that this is not a single object query. I've seen this before - it wants Scenario to be the first referenced table in the query, but I cannot for the life of me figure out how to write this with Scenario first in the query. When I do, then I get messages about the index() function not being available as that is on the ListJoin.

Any clues?

 
 

Back to the top