简体   繁体   English

Google App Engine Java:查询子对象

[英]Google App Engine Java: Query on a child object

Question is related to Google app engine Java. 问题与Google App Engine Java有关。

I have two objects Employee, Address. 我有两个对象Employee,Address。 Each employee has a list of addresses init and also has a String status of current/retired/left/fired. 每个员工都有一个地址初始化列表,并且具有当前/退休/离开/解雇的字符串状态。

Now I want to get a list of all my current employees who are Houston based. 现在,我想获得我在休斯顿的所有现有雇员的清单。

Class Employee {
    @Persistent(mappedBy="employee")
    List<Address> addresses;
    String status;
}

Class Address {
    @Persistent 
    private Employee employee;
    String address1;
    String city;
    String zip;
}

On my db class how do tell my query to do what i need. 在我的数据库类上,如何告诉我的查询做我需要的事情。

Query query = pm.newQuery(Employee.class, whereClause.toString());

List<Employee> empList = (List<Employee>) query.executeWithArray(paramValues.toArray());

When I set my status parameter to current, it will give me a list of current employees, how do i add the condition of "Houston" into my query so that I dont have to do the filter by myself. 当我将状态参数设置为current时,它将为我提供当前雇员的列表,如何将“休斯顿”的条件添加到查询中,这样我就不必自己进行过滤。

I feel that I am missing something. 我觉得我缺少什么。 Appreciate you help. 感谢您的帮助。

This would require a join, and so isn't possible in a query on App Engine. 这将需要加入,因此无法在App Engine上进行查询。 Your best option would be to query on all address entities from Houston, then fetch their Employee records and filter (in memory) by status. 最好的选择是查询休斯顿的所有地址实体,然后获取其员工记录并按状态过滤(在内存中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM