0

I have added new named query:

@Entity(name = "books")
@NamedQueries({
        @NamedQuery(name = "books.findByCategoryId",
                query = "SELECT DISTINCT b.* FROM books b WHERE b.categoryId =:categoryId")
})
public class Book implements Serializable {

I use Hibernate DAO implementation:

@Override
    public Set<Book> findByCategory(Long categoryId) {
        return  new LinkedHashSet<Book>( sessionFactory.getCurrentSession().
                getNamedQuery("books.findByCategoryId").
                setParameter("categoryId", categoryId).list());
    }

For some reason in IDE I see: Cannot resolve query 'books.findByCategoryId'. When I start the application I'm getting:

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)
0

1 Answer 1

1

The Hibernate error: "Errors in named queries: books.findByCategoryId" means that you have a syntax issue with the query. The message from your IDE is a bit misleading. As pointed out by @Piotr change "b.*" to "b" in your query.

The The Hibernate Query Language doesn't mention a wildcard.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.