2015-07-02 103 views
0

完整的錯誤信息:休眠錯誤 - QuerySyntaxException:管理員沒有映射錯誤

11:49:51,896 INFO [stdout] (http-localhost-127.0.0.1-8080-1) 
javax.ejb.EJBException: 
java.lang.IllegalArgumentException: 
org.hibernate.hql.internal.ast.QuerySyntaxException: 
    administrator is not mapped [SELECT ad FROM administrator ad WHERE ad.adminID='123' AND ad.Password='123'] 
@Stateless 
public class ManageAdministrator implements ManageAdministratorRemote { 
    @PersistenceContext(unitName = "JPADB") 
    private EntityManager entityManager;  

    public ManageAdministrator() { 
    } 

    public Administrator createAdministrator(Administrator adminID) 
    { 
     entityManager.persist(adminID); 
     System.out.println("Inside create administrator"); 
     entityManager.flush(); 
     return adminID; 
    } 

    public List retrieveAllAdministrators() 
    { 
     String q = "SELECT ad from " + Administrator.class.getName() + " ad"; 
     Query query = entityManager.createQuery(q); 
     List administrators = (List) query.getResultList(); 
     return administrators; 
    } 

    @Override 
    public Administrator adminLogin(Administrator adminID) { 
     try { 
      String q ="SELECT ad FROM administrator ad WHERE ad.adminID='" 
        + adminID.getAdminID() +"'" 
        + " AND ad.Password='" 
        + adminID.getPassword() +"'"; 

      Query query = entityManager.createQuery(q); 
      query.setMaxResults(1); 
      //query.setParameter("logInEmail", admin.getLogInEmail()); 
      System.out.println(q); 
      return (Administrator) query.getSingleResult(); 
     } 
     catch(NoResultException e) 
     { 
       return null; 
     } 
    } 

    @Override 
    public int stringToInt(String word) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

可我知道什麼是此錯誤的原因是什麼?

+0

persistence.xml中是管理類可用? –

+0

確實,你可以發佈persistence.xml,spring配置和Administrator實體嗎? – ConMan

回答

2

您的實體類似乎是管理員(在開始時大寫字母爲A),而在您的查詢中使用管理員(在開始時使用小寫字母a).JPA查詢區分大小寫。

更改這行代碼:

String q ="SELECT ad FROM Administrator ad WHERE ad.adminID='" 
+0

謝謝,問題解決了。 :) – linnndaaa