对象化和实体组
这是所有对象化/应用程序引擎专家的问题:
我通过将父对象的键存储在子对象中来创建具有父/子关系的对象。 它存储在 Key 类型的对象中。例如,假设我有一个汽车对象和轮胎对象。 轮胎对象将父键存储在 Key 类型的变量中。
@Entity
Public class Tire{
@Id Long id;
Key<Car> ParentKey;
int size;
}
在我的应用程序中,我需要获取某辆车的所有轮胎。我可以通过查询来做到这一点: 轮胎 轮胎 = oft.query(Tire.class).filter("ParentKey",carKey).get();
这是实现这一目标的适当方法吗?这会导致实体组出现任何问题吗?这对于大量汽车和轮胎有效吗?
Here is a question for all the objectify/ app engine gurus out there:
I am creating ojectes with a parent/child relationship by storing the key of the parent object in the child.
This is stored in a object of type Key. For example let's say I have a car object and tire objects.
The tire objects store the parent key in a variable of type Key.
@Entity
Public class Tire{
@Id Long id;
Key<Car> ParentKey;
int size;
}
In my app I will need to get all the tires given a certain car. I can do this with a query:
Tire tires = oft.query(Tire.class).filter("ParentKey",carKey).get();
Is this an approipriate way to accomplish this? Will this cause any issues with entity groups? Will this be efficient for a large number of cars and tires?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前,您还没有创建父/子关系,至少按照 应用引擎。查看文档:添加父/子关系可以加快速度,因为汽车及其轮胎将物理存储在一起,但如果在某些时候不再需要它们,则可能很难将其移除。
要使用 Objectify 创建父/子关系,请添加
@Parent
注释:现在,为了获取属于特定汽车的所有轮胎:
Right now you're not creating a parent/child relationship, at least as is defined by app engine. Check out the documentation: adding a parent/child relationship can speed up things because the car and its tyres will be stored physically together, but they can be difficult to remove if at some point they are not longer needed.
To create a parent/child relationship using Objectify, add the
@Parent
annotation:Now, in order to get all the tires that belong to a specific car:
我正在使用完全相同的方式 - 没问题。
我没有看到与实体组有任何冲突,并且它对于大型组(至少对于数千个实体)工作正常
PS如果您需要获取属于同一组的数据 - 您不需要使用 GAE组。更重要的是:实体组最适合事务,而不是过滤。
I'm using exactly same way - no problem.
I don't see there any conflicts with entity groups, and it's working fine for a large groups (at least for a thousands of entities)
P.S. If you need to fetch data that belongs to same group - you don't need to use GAE groups. Even more: entity groups are best for transactions, not for filtering.