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();
//??? ??? ??? }
//??? ??? });
//??? }