如何在Google App Engine中由ManyToOne方面的父母过滤实体 [英] How to filter entities by their parents in ManyToOne side in Google App Engine
问题描述
我使用Google App Engine。当我试图做这样的JPA查询时:
SELECT p FROM参与者p
WHERE p.party.id =:partyKey AND p.name =:participantName
我得到以下错误:
产生的原因:org.datanucleus.store.appengine.FatalNucleusUserException:
从参与者p其中p.party.id =:partyKey和p .name =:participantName:
如果嵌入子对象,则只能引用子对象的属性。
我将Party对象的关键字作为参数指定给partyKey命名参数。 p>
模型如下:派对有多个参与者。
我想根据参与者的名称和参与者来查询参与者。我只是无法弄清楚如何使用派对过滤。我有什么选择?
我也尝试了以下查询:
SELECT FROM Participant p
WHERE p.party =:party AND p.name =:participantName
但会导致以下错误:
原因:org.datanucleus.store.appengine.FatalNucleusUserException:
SELECT FROM参与者p WHERE p.party =:派对AND p.name =:参与者名称:
参数值的键没有父项。
您可以通过声明父pk来执行祖先查询领域。然后,您可以使用该字段筛选子对象。在文档中检查有关parent-pk的部分。一>(和是的确定以读此讨论)。
更新:对于JPA,看起来你会这样声明:
@Extension(vendorName =datanucleus,key =gae.parent-pk)
private long parentId ;
您可能还想阅读查询关键参数博客帖子。
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.
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.
这篇关于如何在Google App Engine中由ManyToOne方面的父母过滤实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!