AppEngine JDO-QL : Problem with multiple AND and OR in query
Posted
by KlasE
on Stack Overflow
See other posts from Stack Overflow
or by KlasE
Published on 2010-05-16T09:41:03Z
Indexed on
2010/05/16
9:50 UTC
Read the original article
Hit count: 399
Hi, I'm working with App Engine(Java/JDO) and are trying to do some querying with lists.
So I have the following class:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class MyEntity
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;
@Persistent
List<String> tags = new ArrayList<String>();
@Persistent
String otherVar;
}
The following JDO-QL works for me:
( tags.contains('a') || tags.contains('b') || tags.contains('c') || tags.contains('d') ) && otherVar > 'a' && otherVar < 'z'
This seem to return all results where tags has one or more strings with one or more of the given values and together with the inequality search on otherVar
But the following do not work:
(tags.contains('a') || tags.contains('_a')) && (tags.contains('b') || tags.contains('_b')) && otherVar > 'a' && otherVar < 'z'
In this case I want all hits where there is at least one a (either a or _a) and one b (either b or _b) together with the inequality search as before.
But the problem is that I also get back the results where there is a but no b, which is not what I want.
Maybe I have missed something obvious, or done a coding error, or possibly there is a restriction on how you can write these queries in appengine, so any tips or help would be very welcome.
Regards Klas
© Stack Overflow or respective owner