org.hibernate.util.JDBCExceptionReporter - SQL Error: 17006, SQLState: null... 列名无效.could not exe...

xiaoxiao2021-03-01  51

2018-07-23 15:19:02,374 [http-bio-8080-exec-9] WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: 17006, SQLState: null 2018-07-23 15:19:02,374 [http-bio-8080-exec-9] ERROR org.hibernate.util.JDBCExceptionReporter - 列名无效 2018-07-23 15:19:02,375 [http-bio-8080-exec-9] ERROR com.css.login.LocalUserLogin - could not execute query org.hibernate.exception.GenericJDBCException: could not execute query

新发现的一个bug,刚开始以为是缺少字段,但是把执行的SQL放在plsql执行之后,没问题 ,成功查出,但是java代码中执行的时候就是不行,后来网上查了下,原因存在两种,

1.在用数组接收查询结果集合的时候,只查询了一个字段,在查询字段再加一个字段或者换成“*”即可解决问题;

原SQL:select 字段1 from 表名;

改过之后SQL:select 字段1,字段2 from 表名;

或者select * from 表名;

 

2.HIbernate 获取集合的时候指定了错误的字段名称:

sb.append("SELECT  A.字段1  as 别名1  FROM 表A");

 SQLQuery query = HibernateUtil.currentSession().createSQLQuery(sb.toString());  List<String>   wyList = (List<String>) query.addScalar("name", Hibernate.STRING).list();

 

将name改为别名1即可

转载请注明原文地址: https://www.6miu.com/read-3856943.html

最新回复(0)