Menu

Group by feature in entity API

2011-12-01
2012-09-09
  • Vasanth Kamatgi

    Vasanth Kamatgi - 2011-12-01

    Looking at EntityFindImpl, I see that GROUP BY clause is added only when
    functions are used. I am not able to understand it completely. It would be
    great if an example usage of "group by" using entity api is shared.

    Thanks

    Vasanth

     
  • Vasanth Kamatgi

    Vasanth Kamatgi - 2011-12-01

    Actually, I am trying to port the following mysql query, using entity api.

    SELECT GROUP_CONCAT(COLUMNA), GROUP_CONCAT(COLUMNB), COLUMNC, COUNT(COLUMNC) COUNTC, COLUMND FROM TABLE_A WHERE COLUMNC IN ('X','Y','Z') GROUP BY COLUMND HAVING COUNTC = 3 ORDER BY MIN(COLUMNE);
    

    TableA is already defined as an entity.

    Help in porting this into the equivalent EntityFind would be a great help for
    me.

    Thanks,

    Vasanth

     
  • David E. Jones

    David E. Jones - 2011-12-04

    For very custom/complex queries, and in general for queries you can't do with
    the normal Entity Facade API (ie EntityFind, EntityList, etc) you can use the
    EntityFacade.getConnection(groupName) method.

    If the result columns match an entity or view entity you can also run custom
    SQL queries and get a EntityListIterator object back (instead of a plain JDBC
    ResultSet) using the EntityFacade.sqlFind(String sql, List<Object>
    sqlParameterList, String entityName, List<String> fieldList) method.

     

Log in to post a comment.