JDO查询帮助(按成分查找菜谱)
我需要一些有关 JDO 查询的帮助。
我有以下实体:
recipe:
@PersistenceCapable
class Recipe{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key;
...
@Persistent(mappedBy = "recipe")
private List<RecipeIngredient> ingredients
}
recipeIngredient:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class RecipeIngredient implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
Integer amount
@Persistent
Key unit
@Persistent
Key ingredient
@Persistent
Recipe recipe
成分:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class Ingredient implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
String name
一个Recipe可以有多个recipeIngredients,其中包含实际成分、成分的数量和单位。
我想按成分获取所有食谱,这些成分仅含有给定的成分,而不是更多。
目前我这样做:
- 按成分名称获取所有成分对象
- 按成分键获取所有配方成分对象
- 按配方成分获取所有配方
- 检查配方中的所有配方成分是否都在之前的配方成分列表中
- 如果是的话 将配方添加到输出列表
我可以这样做吗一个查询?也许类似于拥有的东西?
I need some help with a JDO query.
I have the following Entities:
recipe:
@PersistenceCapable
class Recipe{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key;
...
@Persistent(mappedBy = "recipe")
private List<RecipeIngredient> ingredients
}
recipeIngredient:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class RecipeIngredient implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
Integer amount
@Persistent
Key unit
@Persistent
Key ingredient
@Persistent
Recipe recipe
ingredient:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class Ingredient implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
String name
A Recipe can have several recipeIngredients which holds the actual ingredient, the amount of the ingredient and the unit.
I would like to get all recipes by ingredients which only hold the given ingredients and not more.
At the moment I do this:
- get all ingredient objects by ingredient name
- get all recipeIngredient objects by ingredient key
- get all recipes by recipeIngredient
- check if all recipeIngredients from recipe are in recipeIngredient list from before
- if so add recipe to output list
Can I do this with a query? maybe something similar to having ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试类似...
另请参阅: http://www.datanucleus .org/servlet/forum/listthreads?forum=9
我不使用 Google App Engine,但我确实大量使用 DataNucleus,并且我相信 DataNucleus 是 App Engine 使用的 JDO 的实现。
让我知道这在 App Engine 上是如何工作的,因为我一直在我的应用程序中做同样的事情。
Try something like...
Also take a look at: http://www.datanucleus.org/servlet/forum/listthreads?forum=9
I don't use Google App Engine but I do use DataNucleus heavily and I believe that DataNucleus is the implementation of JDO that the App Engine uses.
Let me know how this works on App Engine as I do this same kind of thing all the time in my apps.