views:

64

answers:

1

I use Google App Engine. When I try to do a JPA query like this:

SELECT p FROM Participant p 
WHERE p.party.id = :partyKey AND p.name=:participantName 

I get the following error

Caused by: org.datanucleus.store.appengine.FatalNucleusUserException: 
SELECT FROM Participant p WHERE p.party.id = :partyKey AND p.name=:participantName: 
Can only reference properties of a sub-object if the sub-object is embedded.

I gave the key of the Party object as a parameter to the "partyKey" named parameter.

The model is like this: Party has multiple Participants.

I want to query a participant based on the party and the name of the participant. I just can't figure out how to filter using the party. What options do I have?

I've also tried the following query:

SELECT FROM Participant p 
WHERE p.party = :party AND p.name=:participantName

but it results in the following error:

Caused by: org.datanucleus.store.appengine.FatalNucleusUserException: 
SELECT FROM Participant p WHERE p.party = :party AND p.name=:participantName: 
Key of parameter value does not have a parent.
+1  A: 

You can do ancestor queries by declaring a parent-pk field. You can then filter the child object using that field. Check the part about "parent-pk" in the documentation (and be sure to read this discussion).

Update: For JPA, it seems you would declare it like this:

@Extension(vendorName="datanucleus", key="gae.parent-pk")
private Long parentId;

You might also want to read the Querying with Key parameters blog post.

Pascal Thivent
I'm using JPA and that documentation is for JDO. How exactly do I declare a parent-pk field?
palto
@palto: Yes, the documentation is for JDO but this applies to JPA too. And I agree, the JPA documentation of GAE sucks big time (it's like Google doesn't want you to use JPA)...
Pascal Thivent