0
org.datanucleus.store.query.QueryCompilerSyntaxException: Identifier expected at character 12 in "u.username== value"

here is the query I'm trying to Execute :

try{
        Query q=em.createQuery("select u from UserJ u where u."+key+"== value");
        q.setParameter("value",value );
        return q.getResultList().isEmpty();
    }
    catch(PersistenceException x)
    {
        System.out.println(x.getLocalizedMessage());}
    finally{    
        em.close();
    }

Where is key is passed by value :"username"

and value is passed by value :"test"

4

1 回答 1

2

您的语法不正确,请尝试以下查询:

Query q = em.createQuery("select u from UserJ u where u."+key+" = :value");
于 2013-02-20T14:29:17.400 回答