日期:2014-05-20 浏览次数:21307 次
public List findAllCardinfo(String userid, Long cardid) {
Session session = HibernateSessionFactory.getSession();
StringBuffer sb = new StringBuffer();
Transaction tx = null;
Query queryObject = null;
try {
tx = session.beginTransaction();
sb
.append("select new com.telezone.vo.CardinfoVO( cinfo.cardid ,cinfo.cardname , oinfo.ownername ,uinfo.username , cinfo.phonenum,cinfo.cardstate,cinfo.createtime,cinfo.otherinfo ) from Cardinfo as cinfo left join cinfo.cardownerinfo as oinfo left join cinfo.userinfo as uinfo where uinfo.userid = :uid ");
// Long 类型 cardid 默认取值 0
if (cardid > 0)
sb.append(" and cinfo.cardid = :cid");
sb.append(" order by cinfo.cardid");
queryObject = session.createQuery(sb.toString());
queryObject.setParameter("uid", userid);
if (cardid > 0)
queryObject.setParameter("cid", cardid);
tx.commit();
} catch (RuntimeException re) {
tx.rollback();
log.error("==CardinfoServices findAllCardinfo failed==", re);
re.printStackTrace();
} finally {
session.close();
}
return queryObject.list();
}