Hibernate的獲取和刪除備份
public int delNews(final List arr_id) {
return ( (Integer)this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException,
HibernateException {
Query q = session.createQuery(
"delete net.csdn.News where arrid in (:ids)");
q.setParameterList("ids", arr_id);
return new Integer(q.executeUpdate());
}
})).intValue();
}
///
public List getNewsList(final int num) {
return (List) getHibernateTemplate().execute( new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String hql = "FROM News n1 order by id desc" ;
Query query = session.createQuery( hql );
query.setMaxResults( num ) ;
List list = query.list();
if ( list.size() > 0 ) {
return list;
} else {
return null;
}
}
});
}