何时在休眠中使用分离标准? [英] when to use detached criteria in hibernate?

查看:96
本文介绍了何时在休眠中使用分离标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时使用分离标准?使用分离标准而不是普通标准获得的优势是什么?

when to use detached criteria? and what is the advantage we get by using detached criterias instead of normal criteria?

Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Some.class);


DetachedCriteria criteria = DetachedCriteria.forClass(Some.class);

谢谢!

Thanks!

推荐答案

根据文档

As per docs


有些应用程序需要在分离模式中创建条件查询,
其中Hibernate会话不可用。这个类可以在任何地方实例化
,然后通过将
一个会话传递给 getExecutableCriteria()来获得一个Criteria。所有方法与Criteria
接口的相应方法具有相同的
语义和行为。

Some applications need to create criteria queries in "detached mode", where the Hibernate session is not available. This class may be instantiated anywhere, and then a Criteria may be obtained by passing a session to getExecutableCriteria(). All methods have the same semantics and behavior as the corresponding methods of the Criteria interface.

这篇关于何时在休眠中使用分离标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆