Class AliasToBeanResultTransformer

java.lang.Object
org.hibernate.transform.AliasToBeanResultTransformer
All Implemented Interfaces:
Serializable, ResultTransformer

public class AliasToBeanResultTransformer extends Object implements ResultTransformer, Serializable
Result transformer that allows to transform a result to a user specified class which will be populated via setter methods or fields matching the alias names.

 List resultWithAliasedBean = s.createCriteria(Enrolment.class)
                        .createAlias("student", "st")
                        .createAlias("course", "co")
                        .setProjection( Projections.projectionList()
                                        .add( Projections.property("co.description"), "courseDescription" )
                        )
                        .setResultTransformer( new AliasToBeanResultTransformer(StudentDTO.class) )
                        .list();
 

StudentDTO dto = (StudentDTO)resultWithAliasedBean.get(0);

See Also:
  • Constructor Details

    • AliasToBeanResultTransformer

      public AliasToBeanResultTransformer(Class resultClass)
  • Method Details

    • transformTuple

      public Object transformTuple(Object[] tuple, String[] aliases)
      Description copied from interface: ResultTransformer
      Tuples are the elements making up each "row" of the query result. The contract here is to transform these elements into the final row.
      Specified by:
      transformTuple in interface ResultTransformer
      Parameters:
      tuple - The result elements
      aliases - The result aliases ("parallel" array to tuple)
      Returns:
      The transformed row.
    • transformList

      public List transformList(List collection)
      Description copied from interface: ResultTransformer
      Here we have an opportunity to perform transformation on the query result as a whole. This might be useful to convert from one collection type to another or to remove duplicates from the result, etc.
      Specified by:
      transformList in interface ResultTransformer
      Parameters:
      collection - The result.
      Returns:
      The transformed result.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object