5 Replies Latest reply on Dec 22, 2004 8:56 AM by stscit04

    EJB QL: Selecting anything different than entity beans

    airmer

      Is it possible in EJB QL to select only some attributes of an entity bean. Something like:

      SELECT OBJECT(b) FROM Customer AS a, IN(a.customerName) AS b

      This select does not work, I know but why?
      What I really want to do, is to select Collections of Value-Objects (Pojo) with EJB QL. It might be very fast and would simplify the source of the session beans.
      Is that possible?

        • 1. Re: EJB QL: Selecting anything different than entity beans
          stscit04

          What you migth want are EJB-Selects, they allow
          you to do something like

          SELECT c.name FROM Customer AS c WHERE c.id=?1

          EJB-Selects are descibed in the JBoss dokumentation
          and are supported by special XDoclet-Tags.


          Regards,

          Stefan

          • 2. Re: EJB QL: Selecting anything different than entity beans
            airmer

            No, your select does only select the name of a single customer.
            What I want to do is to select the names of all customers. Maybe my customer is a very big Entity-Bean. It could be than much faster only to select their names. The result should be a collection of Strings.
            Or it would perfect to select the value-objects of all customers. This would be very flexible.

            • 3. Re: EJB QL: Selecting anything different than entity beans
              stscit04

              Well, just forget the WHERE clause and you will get
              the names of all customers. Anohter possibillity is to define
              load-sets that correspond with the Xdoclet-defined value-objects.
              (You can define more than one VO for an EB).

              Regards,

              Stefan

              • 4. Re: EJB QL: Selecting anything different than entity beans
                airmer

                Hi Stefan,

                Well, just forget the WHERE clause and you will get the names of all customers.
                Correct, but I get all the rest of the customer, too. Try it. JBoss may be not able to give only parts of an Entity-Bean.
                Anohter possibillity is to define load-sets that correspond with the Xdoclet-defined value-objects.
                Yes, that's why selecting VOs whould be very flexible and fast. But how can I select a VO with EJB-QL?

                • 5. Re: EJB QL: Selecting anything different than entity beans
                  stscit04

                  Arne,

                  you should really make yourself familiar with
                  the documentation of Jboss, it will help you understand
                  how ejb-selects are _different_ from ejb-finder methods.

                  They ARE used to retrieve only a single field of
                  an entity bean. You also should take the time
                  and read the chapter about load-sets and other
                  optimizations.

                  Regards,

                  Stefan