[英]Why is Hibernate throwing an invalid column exception? My query runs well in Oracle, but throws an exception in Java code
Constants.java常量.java
public static final String A=" SELECT name as teamName,location as bookingLoc FROM table where emp_ps_id = :empPSID and rownum<2" ;
public static final String A=" SELECT name as team,location as booking FROM table where emp_ps_id = :empPSID and rownum<2" ;
If I use these queries with Hibernate, first one throws an invalid column name exception
and the second one produces correct result.如果我将这些查询与 Hibernate 一起使用,第一个会抛出invalid column name exception
,第二个会产生正确的结果。
public Details getDetails(final String psid) {
final String finalQuery = Constants.A;
return (Details) entityManager.createNativeQuery(finalQuery, Details.class)
.setParameter("empPSID", psid)
.getSingleResult();
}
As no explicit query mapping is given, the implicit mapping is taking place and thus the aliased names and types in the query (those after as
such as teamName
) needs to correspond to fields on the result class Details
.由于没有给出显式查询映射, 隐式映射正在发生,因此查询中的别名和类型(那些在as
teamName
之后的)需要对应于结果 class Details
上的字段。
Synchronizing the aliased names and types between the query and result class will fix the problem.同步查询和结果 class 之间的别名和类型将解决此问题。 Note that every fields on the result class needs to be delivered by the query.请注意,结果 class 中的每个字段都需要由查询传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.