我有一个使用表的 sql 查询。结果集返回到未映射到数据库中的表的 bean 类。代码在这里:
SQLQuery q2=ss.createSQLQuery("select tbl_policy.policyNum as POLICYNUM FROM tbl_policy join tbl_product on tbl_policy.FK_productId = tbl_product.pk_product_id join tbl_code on tbl_policy.FK_codeId = tbl_code.PK_codeId join tbl_agriyear on tbl_policy.FK_agriYearId = tbl_agriyear.pk_agriyear_id where tbl_policy.FK_naturalInsurantId = :p1 and tbl_agriyear.AGRIYEAR =:p2");
q2.addScalar("POLICYNUM", Hibernate.STRING);
List<SearchPolicyBean> lsql = (List<SearchPolicyBean>)q2.list();
bean 类名是: SearchPolicyBean 当我运行它时,在这一行
System.out.println("Finalllll "+lsql.get(0).getPOLICYNUM());
出现此错误:
java.lang.String cannot be cast to BO.SearchPolicyBean