Dynamic fetch plan with navigations [message #379026] |
Thu, 07 August 2008 02:59  |
Eclipse User |
|
|
|
Is it possible to declare a query such that fields of associated objects
are guaranteed to be loaded?
Lets say you have: Catalog <-->n Article <-->n Description
You query for Catalog and want to have certain fields from Article and
Description to be fetched as well.
I am aware of JPA fetch joins. However, due to a subtle omission in the
JPA query grammar, those fetch joins cannot be cascaded.
I also had a look at chapter "Using Queries with Fetch Groups" in the
EclipseLink documentation[1], but I cannot figure out how to specify
object-navigations here.
Kindly appreciate your help,
Frank
[1]
http://wiki.eclipse.org/Using_Advanced_Query_API_(ELUG)#How_to_Query_with_a_Dynamic_Fetch_Group
|
|
|
|
|
|
Re: Dynamic fetch plan with navigations [message #379039 is a reply to message #379035] |
Mon, 11 August 2008 11:38   |
Eclipse User |
|
|
|
> What SQL did you get from using the hint?
Unfortunately, I cannot reproduce the observed behavior. It was like
pre-fetching the first relationship and later fetching on-demand the
nested relationship.
Now I am seeing an exception with the cascading query hint.
Object model: Person with self-reference "friends" as many-to-many
Query:
Query query = entityManager.createQuery("SELECT p FROM Person p");
query.setHint("eclipselink.join-fetch", "p.friends.friends");
resulting SQL:
SELECT t2.ID, t2.FIRSTNAME, t2.LASTNAME, t0.ID, t0.FIRSTNAME, t0.LASTNAME
FROM FRIEND t4, FRIEND t3, PERSON t2, PERSON t1, PERSON t0 WHERE
(((t3.Person_ID = t2.ID) AND (t1.ID = t3.Friend_ID)) AND ((t4.Person_ID =
t1.ID) AND (t0.ID = t4.Friend_ID)))
Exception:
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.pre pareNestedJoinQueryClone(ForeignReferenceMapping.java:1491)
at
org.eclipse.persistence.mappings.CollectionMapping.valueFrom RowInternalWithJoin(CollectionMapping.java:1560)
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.val ueFromRow(ForeignReferenceMapping.java:1338)
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.bui ldCloneFromRow(ForeignReferenceMapping.java:171)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildAttributesIntoWorkingCopyClone(ObjectBuilder.java:1238)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildWorkingCopyCloneFromRow(ObjectBuilder.java:1355)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObjectInUnitOfWork(ObjectBuilder.java:513)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:461)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:413)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.buildOb ject(ObjectLevelReadQuery.java:521)
at
org.eclipse.persistence.queries.ReadAllQuery.registerResultI nUnitOfWork(ReadAllQuery.java:893)
at
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLe velReadQuery(ReadAllQuery.java:486)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute DatabaseQuery(ObjectLevelReadQuery.java:883)
at
org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:666)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute (ObjectLevelReadQuery.java:844)
at
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAll Query.java:456)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute InUnitOfWork(ObjectLevelReadQuery.java:906)
at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2588)
at
org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1178)
at
org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1162)
at
org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1136)
at
org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1118)
at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeRea dQuery(EJBQueryImpl.java:399)
at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultL ist(EJBQueryImpl.java:517)
The exception apart, the SQL statement should use left outer joins,
shouldn't it?
-- Frank
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04549 seconds