gpt4 book ai didi

java - hibernate 错误 - QuerySyntaxException : administrator is not mapped error

转载 作者:行者123 更新时间:2023-12-01 22:15:23 27 4
gpt4 key购买 nike

完整错误消息:

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

我可以知道这个错误的原因是什么吗?

最佳答案

您的实体类似乎是 Administrator(以大写 A 开头),而在查询中您使用 Administrator(以小写 a 开头)。JPA 查询区分大小写。

更改这行代码:

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

关于java - hibernate 错误 - QuerySyntaxException : administrator is not mapped error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177171/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com