关于hibernate,java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to

dkhumanbeat 2015-12-01 04:58:49
ssh小白,用hibernate写了一个demo,运行时出错
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to Po.Info
Action.LoginAction.validate(LoginAction.java:42)
com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:261)
......

项目代码如下
1.LoginAction.java
if(this.getUserName()==null||this.getUserName().length()==0){
addFieldError("userName","用户名不能为空!");
}else{
LoginRegisterInfo info=new LoginRegisterInfo();
list=info.queryInfo("userName",this.getUserName());
if(list.size()==0){
addFieldError("userName","该用户尚未注册!");
}else{
Info ui=new Info();
int count =0;
for(int i=0;i<list.size();i++){
count++;
ui=(Info) list.get(i); //此行为出错行,就是这行!!!!!!!!!!!!!!!!!!!
if(this.getUserName().equals(ui.getUsername())){
if(ui.getPassword().equals(ui.getPassword())){
message=SUCCESS;
}else{
addFieldError("password","登录密码不正确!");
}
}.
.....

2.LoginRegisterInfo.java

public String saveInfo(Info info){
String mess="error";
getSession=new HibernateSessionFactory1();
session=getSession.getSession();
try{
transaction=session.beginTransaction();
session.save(info);
transaction.commit();
mess="success";
return mess;
}catch(Exception e){
message("Register.error"+e);
e.printStackTrace();
return null;
}
}
public List queryInfo(String type,Object value){
getSession=new HibernateSessionFactory1();
session=getSession.getSession();
try{
String hqlsql="select id,username,password from Info where username='"+value+"'";
query = session.createSQLQuery(hqlsql);
//query=session.createQuery(hqlsql);
//query.setParameter(0,value);
System.out.println(hqlsql);
List <Info>list=query.list();
//transaction.commit();
// System.out.print(list.<Info>get(0).getId());
// System.out.print(list.<Info>get(0).getUsername());
// System.out.print(list.<Info>get(0).getPassword());
System.out.println(list.size());
return list;
}catch(Exception e){
message("LoginRegisterInfo类中有异常,异常为:"+e);
e.printStackTrace();
return null;
}
}
...全文
72 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dkhumanbeat 2015-12-02
引用 1 楼 dracularking 的回复:
list.get(i)是对象数组类型?debug确认下,如果是的话,就肯定不能这样强转
请问应该作何修改?list里面是查询数据库后封装的结果
回复
科學信仰 2015-12-01
list.get(i)是对象数组类型?debug确认下,如果是的话,就肯定不能这样强转
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-12-01 04:58
社区公告
暂无公告