源代码如下
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错误提示是类型不能解析 
不知道怎么改
求大神!!!

解决方案 »

  1.   

    hibernate版本过高,应该在3.6.5.Final版本以下的。因为在Hibernate4.0及以上的中,Hibernate.STRING已经过时了,不再使用了
      

  2.   

     public static final NullableType LONG = new LongType();  public static final NullableType SHORT = new ShortType();  public static final NullableType INTEGER = new IntegerType();  public static final NullableType BYTE = new ByteType();  public static final NullableType FLOAT = new FloatType();  public static final NullableType DOUBLE = new DoubleType();  public static final NullableType CHARACTER = new CharacterType();  public static final NullableType STRING = new StringType();  public static final NullableType TIME = new TimeType();  public static final NullableType DATE = new DateType();  public static final NullableType TIMESTAMP = new TimestampType();  public static final NullableType BOOLEAN = new BooleanType();  public static final NullableType TRUE_FALSE = new TrueFalseType();  public static final NullableType YES_NO = new YesNoType();  public static final NullableType BIG_DECIMAL = new BigDecimalType();  public static final NullableType BIG_INTEGER = new BigIntegerType();  public static final NullableType BINARY = new BinaryType();  public static final NullableType WRAPPER_BINARY = new WrapperBinaryType();  public static final NullableType CHAR_ARRAY = new CharArrayType();  public static final NullableType CHARACTER_ARRAY = new CharacterArrayType();  public static final NullableType TEXT = new TextType();  public static final Type BLOB = new BlobType();  public static final Type CLOB = new ClobType();  public static final NullableType CALENDAR = new CalendarType();  public static final NullableType CALENDAR_DATE = new CalendarDateType();  public static final NullableType LOCALE = new LocaleType();  public static final NullableType CURRENCY = new CurrencyType();  public static final NullableType TIMEZONE = new TimeZoneType();  public static final NullableType CLASS = new ClassType();  public static final NullableType SERIALIZABLE = new SerializableType(Serializable.class);  public static final Type OBJECT = new AnyType();