2 Replies Latest reply on Mar 2, 2006 2:38 AM by Martin Ganserer

    Projection

    Martin Ganserer Novice

      Hello,

      how is projection implemented in the current release of JBOSS EJB3?

      In a new project we want to implement a generic report engine. From my point of view only a good projection implementation can do the job.

      Example:

      Object[][] result = em.createQuery("select id,articleNo from Article order by articleNo").getResultList();


      Would this be possible? Or is it a bad approach?

        • 1. Re: Projection
          Bill Burke Master

          A List of Object[] is returned. Also, take a look at the constructor expressions. you could do this:

          public class ArticleSummary {
           public int id;
           public String articleNo;
          
           public ArticleSummary(int id, String article) {...}
          ...
          }
          
          createQuery("select new com.acme.ArticleSummary(a.id, a.articleNo) From Article a");
          
          


          You would get back a list of ArticleSummary objects. EJB QL allocates ArticleSummary calling the constructor with the column parameters you queried.

          • 2. Re: Projection
            Martin Ganserer Novice

            Hi Bill,

            thank you for your response!
            At the moment I am reading a book about Hibernate. In one chapter the book describes projection (in Hibernate) very well. In one example I have seen that Hibernate was able to get a result list without a "hard defined" object like ArticleSummary.
            What I want to get is a list containing properties only, as I want to build a generic reporting tool. Generic in this case means that one session bean can create different result lists for different queries. The whole EJB-QL should be created automatically and should return only a data list (like a simple table) with a fixed number of columns and a specific number of rows.

            This isn't possible in EJB3, is it?