Hibernate Mapping Exception:-9
if("true".equals(map.get("isAudited"))){
isAudited="=";//已审核
}else{
isAudited="<>";//待审核
}
String sql ="SELECT t.ORIGIN_DISTRICT2,t.ORIGIN_TOWN2,t.CORP_NAME,t.CONTACT_PERSON,t.MOBILE_PHONE,t.CORP_TYPE," +
"t.CORP_NATURE2,t.MAIN_PROD_TYPE,t.ANNUAL_SALES,t.ADDRESS_CITY2||t.ADDRESS_DISTRICT2||c.DQMC|| t.ADDRESS " +
"as addr,t.REGIST_TIME,t.CHECK_STATUS FROM (SELECT t.*,c.DQMC AS ADDRESS_DISTRICT2 FROM (SELECT t.*,s.NAME " +
"as CORP_NATURE2,c.DQMC as ADDRESS_CITY2 FROM (SELECT a.NAME99 as ORIGIN_DISTRICT2,b.dqjc as ORIGIN_TOWN2," +
"t.CORP_NAME,t.CONTACT_PERSON,t.MOBILE_PHONE,s.NAME as CORP_TYPE,t.CORP_NATURE,t.MAIN_PROD_TYPE,t.ANNUAL_SALES" +
",t.ADDRESS_CITY,t.ADDRESS_DISTRICT,t.ADDRESS_TOWN,t.ADDRESS,t.REGIST_TIME, t.CHECK_STATUS FROM BASE_CORP_INFO" +
" t LEFT JOIN SYS_DATA_DICT s on t.CORP_TYPE=s.DATA_DICT_NO LEFT JOIN base_coutry a on t.origin_district=(" +
"a.adcode99||'000000') LEFT JOIN chongqing_temp b on t.origin_town=b.dqbm where t.check_status"+isAudited+"3)t LEFT JOIN " +
"SYS_DATA_DICT s on t.CORP_NATURE=s.DATA_DICT_NO LEFT JOIN CHINA_TEMP c on t.ADDRESS_CITY=c.DQBM )t LEFT " +
"JOIN CHINA_TEMP c on t.ADDRESS_DISTRICT=c.DQBM )t LEFT JOIN CHINA_TEMP c on t.ADDRESS_TOWN=c.DQBM order " +
"by t.ORIGIN_DISTRICT2,t.ORIGIN_TOWN2";
Query q=getSession().createSQLQuery(sql);
q.list();
会抛映射异常
使用笨办法解决:
Query q=getSession().createSQLQuery(sql).addScalar("ORIGIN_DISTRICT2", StringType.INSTANCE).addScalar("ORIGIN_TOWN2", StringType.INSTANCE)
.addScalar("CORP_NAME", StringType.INSTANCE).addScalar("CONTACT_PERSON", StringType.INSTANCE)
.addScalar("MOBILE_PHONE", StringType.INSTANCE).addScalar("CORP_TYPE", StringType.INSTANCE)
.addScalar("CORP_NATURE2", StringType.INSTANCE).addScalar("MAIN_PROD_TYPE", StringType.INSTANCE)
.addScalar("ANNUAL_SALES", StringType.INSTANCE).addScalar("addr", StringType.INSTANCE)
.addScalar("REGIST_TIME", StringType.INSTANCE).addScalar("CHECK_STATUS", StringType.INSTANCE);
即指定返回值的类型。有的hibernate版本是Hibernate.STRING,.INTEGER这么指定的。