com.vladmihalcea.hibernate.type.util
Class MapResultTransformer<K,V>

java.lang.Object
  extended by com.vladmihalcea.hibernate.type.util.MapResultTransformer<K,V>
All Implemented Interfaces:
Serializable, 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 javax.persistence.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:
Serialized Form

Field Summary
static String KEY_ALIAS
           
static String VALUE_ALIAS
           
 
Constructor Summary
MapResultTransformer()
           
 
Method Summary
 List transformList(List tuples)
          Return the Map instead of the default List.
 Object transformTuple(Object[] tuple, String[] aliases)
          Transform the tuple into a key/value pair.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_ALIAS

public static final String KEY_ALIAS
See Also:
Constant Field Values

VALUE_ALIAS

public static final String VALUE_ALIAS
See Also:
Constant Field Values
Constructor Detail

MapResultTransformer

public MapResultTransformer()
Method Detail

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.transform.ResultTransformer
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.transform.ResultTransformer
Parameters:
tuples - tuples
Returns:
the Map result set


Copyright © 2020. All rights reserved.