gpt4 book ai didi

java.lang.ClassCastException : org. hibernate.hql.internal.ast.tree.SqlNode 无法转换为 org.hibernate.hql.internal.ast.tree.FromReferenceNode

转载 作者:行者123 更新时间:2023-11-30 06:46:33 31 4
gpt4 key购买 nike

我正在尝试在 JPA 中执行一个 select 语句,这会抛出上述错误。代码是:

TypedQuery<ListPersonsObj> typedQuery = null;
String query = "";
List<ListPersonsObj> list = null;
if (some condition) {
query = "SELECT NEW in.healthelife.DGS.dao.ListPersonsObj"
+ "(c.personId, c.givenName, c.middleName, c.address1, "
+ "c.address2, c.dateOfBirth, "
+ "c.phoneNumber, c.email) FROM Patients c";
typedQuery = EntityManagerUtil.getEntityManager()
.createQuery(query, ListPersonsObj.class);
list = typedQuery.getResultList();
}

ListPersonsObj 类:

public class ListPersonsObj {

private Long personId;
private String givenName;
private String middleName;
private String address1;
private String address2;
private String dateOfBirth;
private String phoneNumber;
private String email;

public ListPersonsObj() {
}

public ListPersonsObj(Long personId, String givenName, String middleName,
String address1, String address2,
String dateOfBirth, String phoneNumber, String email) {
this.personId = personId;
this.givenName = givenName;
this.middleName = middleName;
this.address1 = address1;
this.address2 = address2;
this.dateOfBirth = dateOfBirth;
this.phoneNumber = phoneNumber;
this.email = email;
}

public ListPersonsObj(ListPersonsObj list) {
try {
BeanUtils.copyProperties(this, list);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// .. getters & setters
}

捕获异常

java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode

任何人都可以阐明这一点。

最佳答案

发生这种情况的一个原因是 Hibernate 在 JPQL 的错误位置找到了保留字。

对于这种情况

The problem is with package name

...

The prefix is 'in' instead of 'com'. While parsing the query the 'in' is treated as reserved world

供引用,see this

Stack Overflow 中的相关问题 here

关于java.lang.ClassCastException : org. hibernate.hql.internal.ast.tree.SqlNode 无法转换为 org.hibernate.hql.internal.ast.tree.FromReferenceNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47467447/

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