0

私はインターフェースを持っています

@PersistenceCapable
public interface MyInterface {

    public abstract String getName();

    public abstract void setName(String name);

}

永続層は JDO を使用します。JDO 実装は DataNucleus です。ここで、JDOQL を使用してそのインターフェースのインスタンスを照会したいと考えています。

クエリ query = getPersistenceManager().newQuery(MyInterface.class);

それはうまくいきます。次に、クエリ結果を名前でフィルター処理します。もちろん、インターフェースには属性がありません。その実装の属性は異なる場合があります。MyInterface のインスタンスは、getName() メソッドによってその名前を返します。

このメソッドを JDOQL で使用するにはどうすればよいですか?

私は少し試しました:

  1. query.setFilter("name == \"" + name);
  2. query.setFilter("name() == \"" + name);
  3. query.declareVariables("myPackage.MyInterface myInterface"); query.setFilter("myInterface.name == \"" + name);
  4. query.declareVariables("myPackage.MyInterface myInterface"); query.setFilter("myInterface.name() == \"" + name);

JDO は依然として例外をスローし続けます (一番下を見てください)。これがインターフェイスに適用できるかどうかはわかりませんが、Java Bean 用語のプロパティである get および set アクセサー メソッドがあります。@Persistentインターフェイスの getName() メソッドとその実装にアノテーションを追加しましたが、何も変わりませんでした。

インターフェイス インスタンスのクエリをフィルタリングするにはどうすればよいですか?

前もって感謝します。

JDO がスローする例外を次に示します。

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)
4

1 に答える 1

0

クエリの形式が正しくないようです。例外は無効な文字列リテラルを示し、クエリのサンプルには閉じられていない二重引用符があります。多分あなたはそのようなことを試してみるべきです:

query.setFilter("name == name_value");
query.declareParameters("String name_value");
query.execute(name);
于 2010-09-11T15:13:39.670 に答える