Package com.vladmihalcea.hibernate.query
Class MapResultTransformer<K,V>
- java.lang.Object
-
- com.vladmihalcea.hibernate.query.MapResultTransformer<K,V>
-
- All Implemented Interfaces:
java.io.Serializable
,org.hibernate.transform.ResultTransformer
- Direct Known Subclasses:
MapResultTransformer
public class MapResultTransformer<K,V> extends java.lang.Object implements org.hibernate.transform.ResultTransformer
TheMapResultTransformer
allows us to return aMap
from a JPAQuery
.If there are aliases named as
key
orvalue
, 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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_ALIAS
private java.util.Map<K,V>
result
static java.lang.String
VALUE_ALIAS
-
Constructor Summary
Constructors Constructor Description MapResultTransformer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List
transformList(java.util.List tuples)
Return theMap
instead of the defaultList
.java.lang.Object
transformTuple(java.lang.Object[] tuple, java.lang.String[] aliases)
Transform the tuple into a key/value pair.
-
-
-
Field Detail
-
KEY_ALIAS
public static final java.lang.String KEY_ALIAS
- See Also:
- Constant Field Values
-
VALUE_ALIAS
public static final java.lang.String VALUE_ALIAS
- See Also:
- Constant Field Values
-
-
Method Detail
-
transformTuple
public java.lang.Object transformTuple(java.lang.Object[] tuple, java.lang.String[] aliases)
Transform the tuple into a key/value pair.If there are aliases named as
key
orvalue
, 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 interfaceorg.hibernate.transform.ResultTransformer
- Parameters:
tuple
- tuple to be transformed to a key/value pairaliases
- column aliases- Returns:
- unmodified tuple
-
transformList
public java.util.List transformList(java.util.List tuples)
Return theMap
instead of the defaultList
.- Specified by:
transformList
in interfaceorg.hibernate.transform.ResultTransformer
- Parameters:
tuples
- tuples- Returns:
- the
Map
result set
-
-