How to filter objects by their parents on the ManyToOne side in the Google App Engine

I am using the Google App Engine. When I try to execute a JPA request, for example:

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 Party object key as a parameter to the "partyKey" parameter.

The model is as follows: Party has several members.

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

I also tried the following query:

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

but this leads to 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. 
+4
source share
1 answer

You can fulfill ancestor requests by declaring a parent-pk field. Then you can filter the child using this field. Check out the "parent-pk" section in the documentation (and be sure to read this discussion ).

Update: For JPA, it seems you would declare it as follows:

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

You can also read the โ€œRequest with Key Parametersโ€ message on the blog.

+3
source

Source: https://habr.com/ru/post/1312684/


All Articles