Google App Engine Java:查询子对象
问题与 Google 应用程序引擎 Java 有关。
我有两个对象员工,地址。 每个员工都有一个初始化地址列表,并且还有一个当前/退休/离开/解雇的字符串状态。
现在我想获取休斯顿所有现有员工的列表。
Class Employee {
@Persistent(mappedBy="employee")
List<Address> addresses;
String status;
}
Class Address {
@Persistent
private Employee employee;
String address1;
String city;
String zip;
}
在我的数据库类上如何告诉我的查询执行我需要的操作。
Query query = pm.newQuery(Employee.class, whereClause.toString());
List<Employee> empList = (List<Employee>) query.executeWithArray(paramValues.toArray());
当我将状态参数设置为当前时,它会给我一个当前员工的列表,我如何将“休斯顿”的条件添加到我的查询中,这样我就不必自己进行过滤。
我觉得我错过了一些东西。感谢您的帮助。
Question is related to Google app engine Java.
I have two objects 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.
I feel that I am missing something. Appreciate you help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这需要联接,因此在 App Engine 上的查询中是不可能的。您最好的选择是查询休斯顿的所有地址实体,然后获取其员工记录并按状态过滤(在内存中)。
This would require a join, and so isn't possible in a query on 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.