hibernate list 问题
try{session=HibernateUtil.currentSession();Transactiontx=session.beginTransaction();/...
try{
session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
//t.stu_No,t.stu_name,t.stu_id,t.stu_sex,t.stu_grade,t.stu_gradeNo,t.stu_photo,t.stu_dpt,t.stu_date
String studentQuery = "select * from t_cet as t where t.stu_No=:stu_No and t.stu_id=:stu_id";
Query sqlQuery = session.createSQLQuery(studentQuery);
sqlQuery.setParameter("stu_No", stu_No);
sqlQuery.setParameter("stu_id", stu_id);
List list = sqlQuery.list();
Iterator ite = list.iterator();
if(ite.hasNext()){
student = (Student)ite.next();
}
//student = (Student)session.get(Student.class,stu_No);
tx.commit();
session.clear();
}catch(Exception ex){
这是异常,student是实体类,并有相关配置文件,可以存数据
Ljava.lang.Object; cannot be cast to com.domain.Student 展开
session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
//t.stu_No,t.stu_name,t.stu_id,t.stu_sex,t.stu_grade,t.stu_gradeNo,t.stu_photo,t.stu_dpt,t.stu_date
String studentQuery = "select * from t_cet as t where t.stu_No=:stu_No and t.stu_id=:stu_id";
Query sqlQuery = session.createSQLQuery(studentQuery);
sqlQuery.setParameter("stu_No", stu_No);
sqlQuery.setParameter("stu_id", stu_id);
List list = sqlQuery.list();
Iterator ite = list.iterator();
if(ite.hasNext()){
student = (Student)ite.next();
}
//student = (Student)session.get(Student.class,stu_No);
tx.commit();
session.clear();
}catch(Exception ex){
这是异常,student是实体类,并有相关配置文件,可以存数据
Ljava.lang.Object; cannot be cast to com.domain.Student 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询