Model:
public void getStudentList(PageListData pageList)
throws DataAccessException {
String hql = "from StudentPO";
HibernateDataSource.getHibernateDataSource().get(hql, pageList);
}
1.查询: String sql_0 = "from Teacher s";
List listTea = createQuery(sql_0).list();
或者:
List list=session.createQuery(“select user.name from User user ”).list();
for(int i=0){
System.out.println(list.get(i));
}
2.添加:getSession().save(entity)
///
3.删除: Transaction trans=session.beginTransaction();
String hql=”delete from User user where user.age=18”;
Query queryupdate=session.createQuery(hql);
int ret=queryupdate.executeUpdate();
trans.commit();
或者String hql = " DELETE FROM Student dm WHERE dm.id = ? ";
this.delete(hql,stu.getId());
//
4.修改:Transaction trans=session.beginTransaction();
String hql=”update User user set user.age=20 where user.age=18”;
Query queryupdate=session.createQuery(hql);
int ret=queryupdate.executeUpdate();
trans.commit();
或者:getSession().update(entity);