4 Replies Latest reply on Aug 2, 2005 6:43 PM by ataud

    NamedQuery - basic questions

    epbernard

      It should work fine. You don't have to put the query on the same class. It just has to be a mapped class.
      You can find some samples in the Hibernate annotations test suite (in the query package I guess).

        • 1. Re: NamedQuery - basic questions
          gsnascimento

          I'm having the same problem with Named Queries...

          --
          Givanildo
          SCJP, SCWCD

          • 2. Re: NamedQuery - basic questions

            I have the same problem ...

            @NamedQuery(
            name="findAllABeans",
            queryString="SELECT OBJECT(o) FROM a AS o ORDER BY o.info DESC"
            )

            @NamedQuery(
            name="findAllCBeansByInfo",
            queryString="SELECT OBJECT(o) FROM c AS o WHERE o.info=?1"
            )

            @Stateless
            public class Alfa {
            private EntityManager em;
            ...
            }

            • 3. Re: NamedQuery - basic questions

              Auto-solved ... damn! NamedQueries array is needed ...

              @NamedQueries({
              @NamedQuery(
              name="findAllABeans",
              queryString="SELECT OBJECT(o) FROM a AS o ORDER BY o.info DESC"
              )

              @NamedQuery(
              name="findAllCBeansByInfo",
              queryString="SELECT OBJECT(o) FROM c AS o WHERE o.info=?1"
              )
              })

              @Stateless
              public class Alfa {
              private EntityManager em;
              ...
              }

              • 4. Re: NamedQuery - basic questions

                In class "Alfa", should we use "createNamedQuery" method of EntityManager to get the request ?

                @NamedQueries({
                @NamedQuery(
                name="findAllABeans",
                queryString="SELECT OBJECT(o) FROM a AS o ORDER BY o.info DESC"
                )

                @NamedQuery(
                name="findAllCBeansByInfo",
                queryString="SELECT OBJECT(o) FROM c AS o WHERE o.info=?1"
                )
                })

                @Stateless
                public class Alfa {
                private EntityManager em;

                public void mysMethod() {
                ...
                Query=em.createNamedQuery("findAllCBeansByInfo");
                ....
                }

                }