0 Replies Latest reply on Jun 9, 2005 1:01 PM by Karen Ploski

    Named query not known

    Karen Ploski Newbie

      Need help getting NamedQuery to work. I am able to use other queries successfully.

      Here is the exception I encounter:

      createNamedQuery() returns:

      [java] Exception in doTask()
      [java] org.hibernate.MappingException: Named query not known: Movie.queryMoviesByStudio
      [java] at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:963)
      [java] at org.jboss.ejb3.entity.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:55)
      [java] at com.demos.hibernatemovies.MovieBean.findMoviesByStudio(MovieBean.java:158)

      Here are the key parts of my code.

      In Movie.java:

      @Entity
      @NamedQueries(
      @NamedQuery(
      name="Movie.queryMoviesByStudio",
      queryString="SELECT movie FROM Movie movie
      WHERE movie.studioName = :studioName"
      )
      )
      @Table(name="MOVIE")
      public class Movie implements java.io.Serializable {

      // etc.

      }

      In MovieInterface.java:

      @Remote
      public interface LoadMovieBeanInterface {

      public void findMoviesByStudio(String studioName);

      }

      In MovieBean.java:

      public void findMoviesByStudio(String studioName)
      {

      Query query = manager.createNamedQuery
      ("Movie.queryMoviesByStudio");
      query.setParameter("studioName", studioName);
      Collection movies = query.getResultList();
      // etc.
      }


      Software levels:

      J2SE 1.5.0
      JBoss 4.0.1 SP1
      EJB 3 Preview 5

      I have looked at the Query folder in Hibernate-Annotations download bundle. The query there is package-level, while in my case it is class-level.

      What have I overlooked?

      Thanks to one and all for any help or suggestions.

      - Karen