何时在hibernate中使用Criteria.ALIAS_TO_ENTITY_MAP? [英] when to use Criteria.ALIAS_TO_ENTITY_MAP in hibernate?
问题描述
Criteria.ALIAS_TO_ENTITY_MAP
请帮助我何时使用 Criteria.ALIAS_TO_ENTITY_MAP
。
感谢!
这些通常用于休眠状态下的结果集变换器。阅读 API 或查看<一个href =http://relation.to/2133.lace =noreferrer>示例。一个ResultTransformer是一个不错的简单接口,允许您转换任何Criteria结果元素。
例如您可以使任何Criteria结果作为java.util.Map或作为非实体Bean返回。
您可以阅读 ALIAS_TO_ENTITY_MAP 此处。也就是,
由前两个查询返回的Cat实例持有的小猫集合不会被条件预过滤。如果您只想检索符合条件的小猫,则必须使用ResultTransformer。
List cats = sess.createCriteria(Cat.class)
.createCriteria(kittens,kt)
.add(Restrictions.eq(name,F%))
.setResultTransformer (Criteria.ALIAS_TO_ENTITY_MAP)
.list();
Iterator iter = cats.iterator(); (iter.hasNext()){
Map map =(Map)iter.next();
猫猫=(猫)map.get(Criteria.ROOT_ALIAS);
Cat kitten =(Cat)map.get(kt);
}
I am new to hibernate. i have read below line.
Criteria.ALIAS_TO_ENTITY_MAP
Please help me when to use Criteria.ALIAS_TO_ENTITY_MAP
.
Thanks!
These are generally used with the Result Set Transformers in hibernate. Read the API or see an example. A ResultTransformer is a nice and simple interface that allows you to transform any Criteria result element.
E.g. you can make any Criteria result be returned as a java.util.Map or as a non-entity Bean.
You can read the example for the ALIAS_TO_ENTITY_MAP here. That is,
The kittens collections held by the Cat instances returned by the previous two queries are not pre-filtered by the criteria. If you want to retrieve just the kittens that match the criteria, you must use a ResultTransformer.
List cats = sess.createCriteria(Cat.class)
.createCriteria("kittens", "kt")
.add( Restrictions.eq("name", "F%") )
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();
Iterator iter = cats.iterator();
while ( iter.hasNext() ) {
Map map = (Map) iter.next();
Cat cat = (Cat) map.get(Criteria.ROOT_ALIAS);
Cat kitten = (Cat) map.get("kt");
}
这篇关于何时在hibernate中使用Criteria.ALIAS_TO_ENTITY_MAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!