0 Replies Latest reply on Sep 16, 2005 4:32 PM by manica

    Why no alias substitutions in Projections.sqlGroupProjection

    manica Newbie

      When using Projections.sqlGroupProjection() it is only possible to use the properties of the root entity in the sql. This seems overly limiting. Why not make it available to leverage any of the other table aliases that may exist with a similar syntax used for {alias}?

      For example:

      Projections.sqlGroupProjection(
       "avg({alias}.price) * {user}.state.taxRate as totalPrice"
       "{item}.id having totalPrice between 100 and 200"
       new String[] {"totalPrice"}
       new Type[] {Hibernate.BIG_DECIMAL});
      


      This assumes that an alias of "user" and "item" have been created in the criteria. The irony is that if you hardcode the hibernate generated alias (ie: user1_ or item2_) for the tables, everything works fine. But there is currently no way to programatically determine this alias name.

      Additionally, it would be great to have parameter setting in Projections.
      Projections.sqlGroupProjection(
       "avg({alias}.price) * {user}.state.taxRate as totalPrice"
       "{item}.id having totalPrice between :low and :high"
       new String[] {"totalPrice"}
       new Type[] {Hibernate.BIG_DECIMAL})
       .setParameter("low", myLowValue)
       .setParameter("high", myHighValue);
      


      Obviously, this isn't the right syntax since it would break the existing Projection interface. But the intent is obvious.