Hey Todd,
There are a few different things you can do here:
1. Use the parent-pk filter. It looks something like this:
query = pm.newQuery("select from Account " +
"where parent-pk == keyParam " +
"parameters Key keyParam");
There's a groups thread about this here:
http://groups.google.com/group/google-appengine-java/browse_thread/thread/97ba3209ec6a65de
and the docs are here:
http://code.google.com/appengine/docs/java/datastore/transactions.html#Using_Transactions(search
2. Use the low-level API.
com.google.appengine.api.datastore.Query has a constructor that takes an
Ancestor key.
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Query.html#Query(com.google.appengine.api.datastore.Key)
Hope this helps.
On Mon, Nov 16, 2009 at 4:29 PM, Todd Vierling <[email protected]> wrote:
> Test app to reproduce:
>
> http://ancestortest.latest.duh-test.appspot.com/
>
> Source code:
>
>
> http://ancestortest.latest.duh-test.appspot.com/src/ancestortest/AncestorTestServlet.java
>
> http://ancestortest.latest.duh-test.appspot.com/src/ancestortest/UserAccount.java
>
> http://ancestortest.latest.duh-test.appspot.com/src/ancestortest/UserAccountModification.java
>
> This sample code basically creates two UserAccount objects and
> attaches a UserAccountModification to one of them. Then, a query
> (which, unless the datastore is really slow, should return an empty
> list):
>
> =====
> Query q = em.createQuery("select m from
> UserAccountModification m where m.modTime < :newest and m.owner
> = :owner order by modTime desc");
> q.setParameter("newest", System.currentTimeMillis() -
> 10000L);
> q.setParameter("owner", user1);
> List<UserAccountModification> mods = q.getResultList();
> =====
>
> I get the following exception:
>
> javax.persistence.PersistenceException: SELECT FROM
> UserAccountModification m WHERE m.modTime < :newest and m.owner
> = :owner ORDER BY modTime desc: Key of parameter value does not have a
> parent.
> at
> org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException
> (NucleusJPAHelper.java:264)
> at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:179)
> at ancestortest.AncestorTestServlet.doGet(AncestorTestServlet.java:
> 46)
>
> I must be missing something here. The docs for GAE talk about
> ensuring the use of ancestor filters when inside a transaction, for
> instance, and there's the ANCESTOR IS operator in GQL. However, I
> can't seem to figure out how properly to express this in JPQL (as
> "ANCESTOR IS" is a syntax error there), and there's no docs that I can
> find on doing this in JPA.
>
> The query is meant to find UserAccountModification objects all
> residing under a given "owner", which happens to be the ancestor of
> those objects. Is there a proper expression for this using JPQL?
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=.
>
>
>
--
Ikai Lan
Developer Programs Engineer, Google App Engine
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=.