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, deta开发者_StackOverflow社区chable="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 ?
Try something like...
select r from Recipe r where ingredients.contains(ri) && (ri.ingredient.name.matches(:searchTxt))
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.
精彩评论