Skip to main content

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

You could try,

select sc from Scenario sc, Story s JOIN s.scenarios sc2 WHERE s.id = :st
oryId and sc = sc2 order by index(sc2) asc

How is scenarios  mapped, does it use a JoinTable?  If it doesn't then you
could probably also just add a QueryKey for the index field, or even map it
in Scenario.


BrianRepko wrote:
> 
> 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 = :st
> oryId 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 selec
> t 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?
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.eclipse.org/forums/index.php?t=thread&frm_id=111&S=1b00bfd151289b297688823a00683aca
EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/batch-loading-of-single-object-reporting-that-query-is-not-a-single-object-tp33823753p33864331.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top