In my GAE project I started with JPA 1.0 and this code worked great:
Query query = em.createQuery("SELECT FROM MyImage " +
"WHERE m_Email = :email " +
"And m_Password = :password ", MyImage.class);
query.setParameter("email", email);
query.setParameter("password", password);
But now that I working with JPA 2.0 I get:
FROM clause of query has class util.MyImage but no alias
org.datanucleus.store.query.QueryCompilerSyntaxException: FROM clause of query has class util.MyImage but no alias
at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:233)
at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:79)
at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:269)
at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:825)
at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:458)
at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:57)
at dataBase.DataBase.getMyImageFromDB(DataBase.java:173)
I manged to get it work with CriteriaQuery but the code is not readable and a little bit messy.
Any idea how to fix this exception?
I think you need to define an alias for your class like this:
Query query = em.createQuery("SELECT i FROM MyImage i " +
"WHERE i.m_Email = :email " +
"And i.m_Password = :password ", MyImage.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With