Criteria APIでは(面倒なことをせずに)あなたが求めていることは不可能だと思います。APIのメソッドはどれもコレクション(あなたの場合はマップ)を返しません。リストのみを返します。
したがって、できることは、最初で唯一の要素がマップになるシングルトンリストを返す独自のResultTransformerを作成することです...しかし、それは私の意見では少し厄介です。
そんな感じ :
public class MyResultTransformer implements ResultTransformer {
public Object transformTuple(Object[] tuple, String[] aliases) {
return tuple;
}
public List transformList(List collection) {
Map result = new LinkedHashMap(); // to preserve order
// build the map from the collection
...
return Collections.singletonList(result);
}
}
2つの要素(Colorとcount)のみを持つタプルを取得するには、Criteria.setProjections()メソッドを使用します。