//StudentServicepublicclassStudentService{private StudentDao dao =newStudentDao();public Student findById(int id){
Session session = HibernateUtil.findSession();
Transaction tx = session.beginTransaction();
Student stu = null;try{
stu = dao.selectById(id);// tx.commit();}catch(Exception e){
e.printStackTrace();
tx.rollback();}return stu;}}
//测试@TestpublicvoidtestFindStudent(){
StudentService ser =newStudentService();
Student stu = ser.findById(1);//多对多:关联出所有老师信息//反过来,查询单个老师,也可以同时关联出学生集合对像(略)
System.out.println(stu.getTeaches());}