Spring Security Hibernate MySQL Uzivatel(用户)未映射

时间:2014-03-05 18:29:10

标签: java mysql spring hibernate spring-mvc

我使用Hibernate实现了Spring Security,但它没有用。我收到了这个错误:

org.hibernate.hql.ast.QuerySyntaxException: Uzivatel is not mapped [from Uzivatel u where u.username = :username]
org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
...

哪里可能出错?

我的UzivatelDaoImpl.class

@Repository
public class UzivatelDaoImpl implements UzivatelDao{
@Autowired  
    private SessionFactory session;

private Session openSession() {
    return session.getCurrentSession();
}

@SuppressWarnings("unchecked")
@Override
public Uzivatel getUzivatel(String username) {
    List<Uzivatel> uzivatelList = new ArrayList<Uzivatel>();
    Query query = openSession().createQuery("from Uzivatel u where u.username = :username");
    query.setParameter("username", username);
    uzivatelList = query.list();
    if (uzivatelList.size() > 0)
        return (Uzivatel) uzivatelList.get(0);
    else
        return null;
}
}

1 个答案:

答案 0 :(得分:1)

可能你没有在hibernate.cfg.xml中映射实体,或者在Uzivatel类中没有@Entity注释。