首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring + hibernate 查詢中除去重複

2013-09-30 
spring + hibernate 查詢中去掉重複??? @SuppressWarnings(unchecked)??? public ListAddressBean fin

spring + hibernate 查詢中去掉重複


??? @SuppressWarnings("unchecked")
??? public List<AddressBean> findAllCityList() {
??? ??? return (List<AddressBean>) getHibernateTemplate().execute(
??? ??? ??? ??? new HibernateCallback() {
??? ??? ??? ??? ??? public Object doInHibernate(Session session)
??? ??? ??? ??? ??? ??? ??? throws HibernateException, SQLException {
??? ??? ??? ??? ??? ??? Criteria criteria = session.createCriteria(AddressBean.class);
??? ??? ??? ??? ??? ??? // 條件
??? ??? ??? ??? ??? ??? criteria.setProjection(Projections.distinct(
??? ??? ??? ??? ??? ??? ??? ??? Projections.projectionList().add(Projections.property("city"))
??? ??? ??? ??? ??? ??? ));
??? ??? ??? ??? ??? ??? criteria.add(Restrictions.in("status",new Integer[] { 1 }));
??? ??? ??? ??? ??? ??? criteria.addOrder(Order.desc("addressId"));
??? ??? ??? ??? ??? ??? return criteria.list();
??? ??? ??? ??? ??? }
??? ??? ??? ??? });
??? }
//??? @SuppressWarnings("unchecked")
//??? public List<AddressBean> findAllCityList() {
//??? ??? return (List<AddressBean>) getHibernateTemplate().execute(new HibernateCallback() {
//??? ??? ??? public Object doInHibernate(Session session)throws HibernateException, SQLException {
//??? ??? ??? ??? return session.createQuery("SELECT DISTINCT(a.city) FROM AddressBean a WHERE a.status=:status").setInteger("status", 1).list();
//??? ??? ??? }
//??? ??? });
//??? }

热点排行