hibernate3学习笔记(七) Criteria Queries - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-20
erator.next());72. }73.74. criteria = session.createCriteria(User.class);75. criteria.setProjection(Projections.avg("age"));76. users = criteria.list();77. iterator = users.iterator();78. while (iterator.hasNext()) {79. System.out.println(iterator.next());80. }81.82. criteria = session.createCriteria(User.class);83. criteria.setProjection(Projections.groupProperty("age"));84. users = criteria.list();85. iterator = users.iterator();86. while (iterator.hasNext()) {87. System.out.println(iterator.next());88. }89.90. ProjectionList projectionList = Projections.projectionList();91. projectionList.add(Projections.groupProperty("age"));92. projectionList.add(Projections.groupProperty("name"));93. projectionList.add(Projections.rowCount());94. criteria = session.createCriteria(User.class);95. criteria.setProjection(projectionList);96. users = criteria.list();97. iterator = users.iterator();98. while(iterator.hasNext()) {99. Object[] o = (Object[]) iterator.next();100. System.out.println(o[0] + "\t" + o[1] + "\t" + o[2]);101. }102.103. criteria = session.createCriteria(User.class);104. criteria.add(Property.forName("name").like("%ya%"));105. criteria.addOrder(Property.forName("age").desc());106. users = criteria.list();107. printUserInfo(users);108.109. User user = new User();110. user.setAge(new Integer(26));111. criteria = session.createCriteria(User.class);112. criteria.add(Example.create(user));113. users = criteria.list();114. printUserInfo(users);115.116.117. session.close();118. sessionFactory.close();119. }120.121. public static void printUserInfo(List<?> users){122.123. Iterator<?> iterator = users.iterator();124. System.out.println("id \t name/age");125. while (iterator.hasNext()) {126. User user = (User) iterator.next();127. System.out.println(user.getId() + " \t " + user.getName() + "/" + user.getAge());128. }129. }130.}
hibernate3学习笔记(七) Criteria Queries(2)时间:2011-02-02 csdn博客 沈斌运行结果如下: 15:41:36,312 WARN ConfigurationFactory:127 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Java/MyEclipse%206.0/workspace/hb3demo/ehcache-1.2.3.jar!/ehcache-failsafe.xml15:41:36,750 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.15:41:36,781 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于hibernate3学习笔记(七) Criteria Queries - 编程入门网的所有评论