日期:2014-05-19  浏览次数:20699 次

菜鸟问题 Hibernate.STRING 类型出错
源代码如下
package org.com.dao.impl;

import javax.annotation.Resource;

import java.util.Iterator;
import java.util.List;

import org.com.dao.PersonDAO;
import org.com.model.User;
import org.com.model.Person;
import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.Query;
import org.hibernate.type.Type;
import org.springframework.stereotype.Repository;

@Resource
public class PersonDAOImpl implements PersonDAO
{
private SessionFactory sessionFactory;

public boolean login(User user)
{
String hql="from User where username=? and password=? and role=?";
String[] params=new String[] {user.getUsername(),user.getPassword(),user.getRole()};

@SuppressWarnings("deprecation")
Type[] types=new Type[]{Hibernate.STRING,Hibernate.STRING,Hibernate.STRING};
 
Query query=sessionFactory.getCurrentSession().createQuery(hql);
query.setParameters(params,types);
Iterator<?> iter=query.iterate();
if(iter.hasNext())
{
return true;
}
return false;
}

public void add(Person person)
{
sessionFactory.getCurrentSession().save(person);
}

public void update(Person person)
{
Person old=(Person)sessionFactory.getCurrentSession().get(Person.class,person.getPersonid());
old.setName(person.getName());
}

public void delete(int personid)
{
Person per=(Person)sessionFactory.getCurrentSession().get(Person.class,personid);
sessionFactory.getCurrentSession().delete(per);
}

@SuppressWarnings("unchecked")
public List<Person> getPersons()
{
return sessionFactory.getCurrentSession().createQuery("from Person").list();
}


}

红色的那一行代码有问题
我用的是Eclipse+Struts2+Hibernate4.0+Spring3.0

错误提示是类型不能解析 
不知道怎么改
求大神!!!

------解决方案--------------------
接分咯
------解决方案--------------------
分给点呗~~