首页 > 代码库 > 开发过程遇到的问题
开发过程遇到的问题
1.hibernate 原生sql查询问题:
1 public void getNurseStatInfo() { 2 String sql = "select ‘col018‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘932a9b81000080810af4‘ " 3 + "union select ‘col024‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘7ca18efa000b0f7d44dc‘ " 4 + "union select ‘col032‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘27f913b6000080e515e0‘ " 5 + "union select ‘col056‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘243c447a00000f7d6958‘ " 6 + "union select ‘col062‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘f786355d001c6a81ea34‘ " 7 + "union select ‘col027‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘3f03ade200020f7d4b1c‘ " 8 + "union select ‘col059‘ id,count(*) count from PHC_RECORD_CARD t where t.phc_model_def_id=‘0305c2e600d57f1509a0‘ "; 9 List<NurseStatInfo> statList = phcRecordCardDao.getEntityManager().createNativeQuery(sql, NurseStatInfo.class).getResultList();10 System.out.println("-----------------------------");11 for (NurseStatInfo info : statList) {12 System.out.println(info.getId());13 System.out.println(info.getCount());14 }15 }
1 import javax.persistence.Entity; 2 import javax.persistence.Id; 3 4 @Entity 5 public class NurseStatInfo { 6 @Id 7 private String id; 8 private int count; 9 10 public String getId() {11 return id;12 }13 public void setId(String id) {14 this.id = id;15 }16 public int getCount() {17 return count;18 }19 public void setCount(int count) {20 this.count = count;21 }22 23 }
NurseStatInfo类中需要加@Entity、@Id两个注解,不然会报以下错误:
Caused by: org.hibernate.MappingException: Unknown entity
参考网站:http://stackoverflow.com/questions/30595445/how-to-map-a-native-query-to-a-pojo-when-i-do-not-have-any-entity-on-my-project
开发过程遇到的问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。