Class MapResultTransformer<K,V>

java.lang.Object
io.hypersistence.utils.hibernate.query.MapResultTransformer<K,V>
All Implemented Interfaces:
Serializable, org.hibernate.query.ResultListTransformer, org.hibernate.query.TupleTransformer, org.hibernate.transform.ResultTransformer

public class MapResultTransformer<K,V> extends Object implements org.hibernate.transform.ResultTransformer
The MapResultTransformer allows us to return a Map from a JPA Query.

If there are aliases named as key or value, then those will be used.

Otherwise, the first column value is the key while the second one is the Map value.

For more details about how to use it, check out this article on vladmihalcea.com.

Since:
2.9.0
Author:
Vlad Mihalcea
See Also:
  • Field Details

  • Constructor Details

    • MapResultTransformer

      public MapResultTransformer()
  • Method Details

    • transformTuple

      public Object transformTuple(Object[] tuple, String[] aliases)
      Transform the tuple into a key/value pair.

      If there are aliases named as key or value, then those will be used.

      Otherwise, the first column value is the key while the second one is the Map value.

      Specified by:
      transformTuple in interface org.hibernate.query.TupleTransformer<K>
      Parameters:
      tuple - tuple to be transformed to a key/value pair
      aliases - column aliases
      Returns:
      unmodified tuple
    • transformList

      public List transformList(List tuples)
      Return the Map instead of the default List.
      Specified by:
      transformList in interface org.hibernate.query.ResultListTransformer<K>
      Specified by:
      transformList in interface org.hibernate.transform.ResultTransformer<K>
      Parameters:
      tuples - tuples
      Returns:
      the Map result set