Hibernate 列名无效 错误的一种原因
产生报错的场景:
1、Hibernate使用纯sql方式查询;
2、查询出来的结果拼装成一个VO对象。
产生报错的原因:
1、VO对象中为了拼装结果,有getXxx方法,用于拼装和组合结果;
2、select出来的列中,没有getXxx对应的属性。
如上,Hibernate就会报“列名无效”的错误。
解决方法,select出来的列中包含xxx。
比如:
select t1.a as a, t1.b as b, t1.c as c, t2.d as d from table1 t1 left join table2 t2 on t1.e=t2.e
class VO { private String a; private String b; private String c; private String d; //getter and setter public String getXxx() { return a + b; }}