【问题标题】:JDO query help (find recipes by ingredients)JDO 查询帮助(按成分查找食谱)
【发布时间】:2011-05-24 22:12:45
【问题描述】:

我需要一些有关 JDO 查询的帮助。

我有以下实体:

食谱:

@PersistenceCapable
class Recipe{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long key;

    ...

    @Persistent(mappedBy = "recipe")
    private List<RecipeIngredient> ingredients
}

配方成分:

@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

一个配方可以有几个配方成分,其中包含实际成分、成分的数量和单位。

我想按仅包含给定成分而不是更多成分的成分获取所有食谱。

目前我这样做:

  • 按成分名称获取所有成分对象
  • 通过成分键获取所有 recipeIngredient 对象
  • 按 recipeIngredient 获取所有食谱
  • 检查recipe中的所有recipeIngredients是否在之前的recipeIngredient列表中
  • 如果是这样,请将配方添加到输出列表

我可以通过查询来做到这一点吗?也许类似于拥有的东西?

【问题讨论】:

    标签: java google-app-engine jdo


    【解决方案1】:

    尝试类似...

    从配方 r 中选择 r 其中成分.contains(ri) && (ri.ingredient.name.matches(:searchTxt))

    另请看:http://www.datanucleus.org/servlet/forum/listthreads?forum=9

    我不使用 Google App Engine,但我确实大量使用 DataNucleus,并且我相信 DataNucleus 是 App Engine 使用的 JDO 的实现。

    让我知道这在 App Engine 上是如何工作的,因为我一直在我的应用中做同样的事情。

    【讨论】:

    • 不知何故我错过了这个答案。会尽快检查的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多