开发过程遇到的问题
Posted Aaronqcd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发过程遇到的问题相关的知识,希望对你有一定的参考价值。
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
以上是关于开发过程遇到的问题的主要内容,如果未能解决你的问题,请参考以下文章