//方法一
Session session =sf.openSession();
Transaction tr =session.beginTransaction();
Query query=session.createQuery("from StudentBean where parentid=?");
query.setInteger(0,id);
List<StudentBean> list =query.list();
tr.commit();
session.close();

//方法二
Session session =sf.openSession();
Transaction tr =session.beginTransaction();
Query query=session .createQuery("from Employee where userName=:userName");
query.setString("userName", name);
List<Employee>list=query.list();
tr.commit();
session.close();