我添加了新的命名查询:
@Entity(name = "books")
@NamedQueries({
@NamedQuery(name = "books.findByCategoryId",
query = "SELECT DISTINCT b.* FROM books b WHERE b.categoryId =:categoryId")
})
public class Book implements Serializable {
我使用 Hibernate DAO 实现:
@Override
public Set<Book> findByCategory(Long categoryId) {
return new LinkedHashSet<Book>( sessionFactory.getCurrentSession().
getNamedQuery("books.findByCategoryId").
setParameter("categoryId", categoryId).list());
}
出于某种原因,我在 IDE 中看到:无法解析查询“books.findByCategoryId”。当我启动应用程序时,我得到:
may 10, 2013 6:55:05 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SpringWebFlow threw load() exception
org.hibernate.HibernateException: Errors in named queries: books.findByCategoryId
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:528)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1760)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1798)