title: How to query for an interface and filter the resultset with JDOQL?
body: <p>I have an interface</p>
  
  <pre><code>@PersistenceCapable
  public interface MyInterface {
  
      public abstract String getName();
  
      public abstract void setName(String name);
  
  }
  </code></pre>
  
  <p>The persistence layer uses JDO. The JDO implementation is DataNucleus. Now I want to query for any instances of that interface with JDOQL. </p>
  
  <p>Query query = getPersistenceManager().newQuery(MyInterface.class);</p>
  
  <p>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. </p>
  
  <p>How do I use this method with JDOQL? </p>
  
  <p>I tried a bit:</p>
  
  <ol>
  <li><code>query.setFilter("name == \"" + name);</code></li>
  <li><code>query.setFilter("name() == \"" + name);</code></li>
  <li><code>query.declareVariables("myPackage.MyInterface myInterface");
  query.setFilter("myInterface.name == \"" + name);</code></li>
  <li><code>query.declareVariables("myPackage.MyInterface myInterface");
  query.setFilter("myInterface.name() == \"" + name);</code></li>
  </ol>
  
  <p>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 <code>@Persistent</code> annotation to the getName() method of the interface and its implementation, but nothing changed.</p>
  
  <p><strong>How do I filter a query for interface instances?</strong></p>
  
  <p>Thanks in advance.</p>
  
  <p>Here is the exception JDO throws:</p>
  
  <pre><code>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)
  </code></pre>