Hi,
I have an interface
@PersistenceCapable
public interface MyInterface {
public abstract String getName();
public abstract void setName(String name);
}
The persistence layer uses JDO. The JDO implementation is DataNucleus. Now I want to query for any instances of that interface with JDOQL.
Query query = getPersistenceManager().newQuery(MyInterface.class);
That works fine. Now I want to filter the query results by name. Of course the interface has no attributes. The attributes of its implementation may differ. Any instance of MyInterface returns its name by the getName() method.
How do I use this method with JDOQL?
I tried a bit:
query.setFilter("name == \"" + name);
query.setFilter("name() == \"" + name);
query.declareVariables("myPackage.MyInterface myInterface"); query.setFilter("myInterface.name == \"" + name);
query.declareVariables("myPackage.MyInterface myInterface"); query.setFilter("myInterface.name() == \"" + name);
JDO still keeps throwing exceptions (look at the bottom). I am not shure if this is applicable to interfaces, but there is a get and a set accesor method, which is a property in java beans terms. I added the @Persistent
annotation to the getName() method of the interface and its implementation, but nothing changed.
How do I filter a query for interface instances?
Thanks in advance.
Here is the exception JDO throws:
org.datanucleus.jdo.NucleusJDOHelper getJDOExceptionForNucleusException
INFO: Exception thrown
Invalid string literal (End of stream): identity.name == "Identity 0
org.datanucleus.exceptions.NucleusUserException: Invalid string literal (End of stream): identity.name == "Identity 0
at org.datanucleus.query.compiler.Lexer.parseStringLiteral(Lexer.java:689)
at org.datanucleus.query.compiler.JDOQLParser.processLiteral(JDOQLParser.java:1012)
at org.datanucleus.query.compiler.JDOQLParser.processPrimary(JDOQLParser.java:678)
at org.datanucleus.query.compiler.JDOQLParser.processUnaryExpression(JDOQLParser.java:621)
at org.datanucleus.query.compiler.JDOQLParser.processMultiplicativeExpression(JDOQLParser.java:547)
at org.datanucleus.query.compiler.JDOQLParser.processAdditiveExpression(JDOQLParser.java:518)
at org.datanucleus.query.compiler.JDOQLParser.processRelationalExpression(JDOQLParser.java:450)
at org.datanucleus.query.compiler.JDOQLParser.processAndExpression(JDOQLParser.java:427)
at org.datanucleus.query.compiler.JDOQLParser.processExclusiveOrExpression(JDOQLParser.java:413)
at org.datanucleus.query.compiler.JDOQLParser.processInclusiveOrExpression(JDOQLParser.java:399)
at org.datanucleus.query.compiler.JDOQLParser.processConditionalAndExpression(JDOQLParser.java:385)
at org.datanucleus.query.compiler.JDOQLParser.processConditionalOrExpression(JDOQLParser.java:366)
at org.datanucleus.query.compiler.JDOQLParser.processExpression(JDOQLParser.java:355)
at org.datanucleus.query.compiler.JDOQLParser.parse(JDOQLParser.java:93)
at org.datanucleus.query.compiler.JavaQueryCompiler.compileFilter(JavaQueryCompiler.java:462)
at org.datanucleus.query.compiler.JDOQLCompiler.compile(JDOQLCompiler.java:101)
at org.datanucleus.store.query.AbstractJDOQLQuery.compileInternal(AbstractJDOQLQuery.java:302)
at org.datanucleus.store.query.Query.compile(Query.java:1446)
at org.datanucleus.jdo.JDOQuery.compile(JDOQuery.java:95)
at net.x0ver.utilities.AbstractJdoRepository.executeQuery(AbstractJdoRepository.java:40)
at net.x0ver.identitymanagement.persistence.JdoIdentityRepository.getIdentities(MyJdoRepository.java:29)
at net.x0ver.identitymanagement.test.MainTest.main(MainTest.java:26)
Exception in thread "main" javax.jdo.JDOUserException: Invalid string literal (End of stream): identity.name == "Identity 0
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:396)
at org.datanucleus.jdo.JDOQuery.compile(JDOQuery.java:99)
at net.x0ver.utilities.AbstractJdoRepository.executeQuery(AbstractJdoRepository.java:40)
at net.x0ver.identitymanagement.persistence.JdoIdentityRepository.getIdentities(MyJdoRepository.java:29)
at net.x0ver.identitymanagement.test.MainTest.main(MainTest.java:26)
NestedThrowablesStackTrace:
Invalid string literal (End of stream): identity.name == "Identity 0
org.datanucleus.exceptions.NucleusUserException: Invalid string literal (End of stream): identity.name == "Identity 0
at org.datanucleus.query.compiler.Lexer.parseStringLiteral(Lexer.java:689)
at org.datanucleus.query.compiler.JDOQLParser.processLiteral(JDOQLParser.java:1012)
at org.datanucleus.query.compiler.JDOQLParser.processPrimary(JDOQLParser.java:678)
at org.datanucleus.query.compiler.JDOQLParser.processUnaryExpression(JDOQLParser.java:621)
at org.datanucleus.query.compiler.JDOQLParser.processMultiplicativeExpression(JDOQLParser.java:547)
at org.datanucleus.query.compiler.JDOQLParser.processAdditiveExpression(JDOQLParser.java:518)
at org.datanucleus.query.compiler.JDOQLParser.processRelationalExpression(JDOQLParser.java:450)
at org.datanucleus.query.compiler.JDOQLParser.processAndExpression(JDOQLParser.java:427)
at org.datanucleus.query.compiler.JDOQLParser.processExclusiveOrExpression(JDOQLParser.java:413)
at org.datanucleus.query.compiler.JDOQLParser.processInclusiveOrExpression(JDOQLParser.java:399)
at org.datanucleus.query.compiler.JDOQLParser.processConditionalAndExpression(JDOQLParser.java:385)
at org.datanucleus.query.compiler.JDOQLParser.processConditionalOrExpression(JDOQLParser.java:366)
at org.datanucleus.query.compiler.JDOQLParser.processExpression(JDOQLParser.java:355)
at org.datanucleus.query.compiler.JDOQLParser.parse(JDOQLParser.java:93)
at org.datanucleus.query.compiler.JavaQueryCompiler.compileFilter(JavaQueryCompiler.java:462)
at org.datanucleus.query.compiler.JDOQLCompiler.compile(JDOQLCompiler.java:101)
at org.datanucleus.store.query.AbstractJDOQLQuery.compileInternal(AbstractJDOQLQuery.java:302)
at org.datanucleus.store.query.Query.compile(Query.java:1446)
at org.datanucleus.jdo.JDOQuery.compile(JDOQuery.java:95)
at net.x0ver.utilities.AbstractJdoRepository.executeQuery(AbstractJdoRepository.java:40)
at net.x0ver.identitymanagement.persistence.JdoIdentityRepository.getIdentities(MyJdoRepository.java:29)
at net.x0ver.identitymanagement.test.MainTest.main(MainTest.java:26)