If you're using JPA annotations, the class with the @NamedQuery annoation must be added to the AnnotationConfiguration object when it is initialized/configured.
Quote:
One thing you should know about named queries is that the class that defines the @NamedQuery tag must be made part of Hibernate's AnnotationConfiguration object. Our User class is added to the AnnotationConfiguration object in our custom HibernateUtil class, so we'll add the NameQuery right before the class declaration of the User.
package com.examscam.model;
import javax.persistence.*;
import org.hibernate.Session;
import com.examscam.HibernateUtil;
@Entity
@Table(name = "user", schema = "examscam")
@NamedQuery(name="user.findByLoginName",
query="from User where loginName = :name" )
public class User { }
Once you have defined your @NamedQuery, and the class in which it is defined is loaded into Hibernate's AnnotationConfiguration, you can use this named query anywhere that you access the Hibernate Session.
http://www.thebookonhibernate.com/HiberBookWeb/learn.jsp?tutorial=08masteringhqlandnamedqueries