Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when to use detached criteria in hibernate?

Tags:

hibernate

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!

like image 983
user1016403 Avatar asked Jan 19 '12 12:01

user1016403


People also ask

What is the purpose of the criteria interface in Hibernate?

The Hibernate Criteria Query Language (HCQL) is used to fetch the records based on the specific criteria. The Criteria interface provides methods to apply criteria such as retreiving all the records of table whose salary is greater than 50000 etc.

What is the benefit of Hibernate Criteria API?

In Hibernate, the Criteria API helps us build criteria query objects dynamically. Criteria is a another technique of data retrieval apart from HQL and native SQL queries. The primary advantage of the Criteria API is that it is intuitively designed to manipulate data without using any hard-coded SQL statements.

What is criteria builder in Hibernate?

Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API, which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions.

What is conjunction in Hibernate?

Hibernate Conjunction, is used to add multiple condition in SQL query separated by AND clause within brackets. To generate following query using Hibernate Criteria we need to use Conjunction.


1 Answers

As per docs

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.

like image 199
user998692 Avatar answered Oct 12 '22 23:10

user998692