4 Replies Latest reply on Dec 19, 2006 9:51 AM by owaind

    EJB QL requires useless item in select list

    owaind

      I have the following EJB QL

      select r.channel.id, sum(se.currentListeners), r from Request r
      left join fetch r.channel c
      left join fetch r.stats s
      left join fetch s.statsEntries se
      where r.createdDate > :startDate and r.createdDate < :endDate
      group by r.channel

      i want to get rid of the r in the select list but it wont let me, can anyone tell me why? in normal sql i wouldnt need the r in the select list. The problem is it takes time to instantiate those Request objects and its totally wasted. I want it to look like this:

      select r.channel.id, sum(se.currentListeners) from Request r
      left join fetch r.channel c
      left join fetch r.stats s
      left join fetch s.statsEntries se
      where r.createdDate > :startDate and r.createdDate < :endDate
      group by r.channel

      lovely that would involve no wasted effort and speed up my query. Can anyone help me i dont understand why i need the r in the select list, is hibernate dumb?

        • 1. Re: EJB QL requires useless item in select list
          epbernard

          No, Hibernate is not dumb.
          Like in SQL, HQL requires the grouby proeprties to be part of the select. You have to include r.channel

          • 2. Re: EJB QL requires useless item in select list
            owaind

            even without the group by the query fails in exactly the same way!

            whats going on hibernate?

            • 3. Re: EJB QL requires useless item in select list
              owaind

              and also sql doesnt require that the group by field is included in the select

              • 4. Re: EJB QL requires useless item in select list
                owaind

                org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=c,role=null,tableName=Channel,tableAlias=channel1_,origin=Request request0_,colums={request0_.channel_FK ,className=com.telepathyproof.adventure.ejb.entity.channel.Channel}}] [select c.id, sum(se.currentListeners) from com.telepathyproof.adventure.ejb.entity.stats.Request r inner join fetch r.channel c left join fetch r.stats s left join fetch s.statsEntries se where r.createdDate > :startDate and r.createdDate < :endDate]
                at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:195)