2012-06-22 3 views
7

내가 JPA 1.0을 시작 별명을 가지고 있으며,이 코드는 큰 일 :클래스 XXX하지만 내 GAE 프로젝트에서

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

하지만 지금은 JPA 2.0 작업 것을 내가 얻을 :

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) 

CriteriaQuery와 함께 작동 시키려면 관리해야하지만 코드를 읽을 수없고 약간 지저분합니다.

이 예외를 수정하는 방법에 대한 아이디어가 있으십니까?

답변

12

난 당신이 같은 클래스의 별칭을 정의 할 필요가 있다고 생각 :와

Query query = em.createQuery("SELECT i FROM MyImage i " + 
          "WHERE i.m_Email = :email " + 
          "And i.m_Password = :password ", MyImage.class); 
+0

간단한 ... 그 당황 :)입니다. 감사 – Rami