Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate Detachedcriteria in hibernate
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
Detachedcriteria in hibernate
1 Answer(s)      2 years and 7 months ago
Posted in : Hibernate


How to apply detachedcriteria in hibernate for given Query?


Advertisement
View Answers

June 1, 2012 at 5:37 PM


Detached Criteria query is a facility provide by Hibernate to write criteria queries in ?detached mode?, where hibernate session is not available. You can instantiate this class anywhere.
For it you have to import

org.hibernate.criterion.DetachedCriteria;

Here is a way to write DetchedCriteria -

DetachedCriteria query = DetachedCriteria.forClass(Employee.class);
query.add(Property.forName("name").eq("Ron"));

Next you can obtain criteria by passing any arbitrary session to getExecutableCriteria() as ?

employeeList = query.getExecutableCriteria(session).list();

Here is Example:-

package net.roseindia.main;

import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;

public class DetachedCriteriaQuery {
    public static void main(String[] args) {
        DetachedCriteria query = DetachedCriteria.forClass(Employee.class);
        query.add(Property.forName("name").eq("Ron"));
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        List<Employee> employeeList = new ArrayList<Employee>();
        employeeList = query.getExecutableCriteria(session).list();
        Iterator it = employeeList.iterator();
        while (it.hasNext()) {
            Employee employee = (Employee) it.next();
            System.out.println("Name : " + employee.getName());
            System.out.println("Salary : " + employee.getSalary());
            System.out.println("Date of Join : " + employee.getDateOfJoin());
        }
        session.close();

    }
}


Related Tutorials/Questions & Answers:
Detachedcriteria in hibernate
Detachedcriteria in hibernate  How to apply detachedcriteria in hibernate for given Query?   Detached Criteria query is a facility provide by Hibernate to write criteria queries in ?detached mode?, where hibernate
Hibernate DetachedCriteria mutiple results in java
Hibernate DetachedCriteria mutiple results in java  This is the SQL... the equivalent to hibernate DetachedCriteria and expected to only have two data as a result. DetachedCriteria dc = getDetachedCriteria(); DetachedCriteria
Advertisements
Hibernate Criteria Detached Subquery Using "Subqueries"
Hibernate Criteria Detached Subquery Using "Subqueries" In this tutorial you will learn how to express a subquery using DetachedCriteria Subqueries. In Hibernate Criteria with the help of DetachedCriteria a query can
Hibernate Criteria Detached Subquery Example
Hibernate Criteria Detached Subquery Example In this tutorial you will learn how to express a subquery using DetachedCriteria. As you have been read in the previous example Hibernate Criteria Detached Query Subquery Hibernate
Hibernate Criteria Nested Properties
Hibernate Criteria Nested Properties Consider the example based on Hibernate Criteria Nested Properties DetachedCriteria detachedCriteria = DetachedCriteria .forClass(Student.class); detachedCriteria.add(Restrictions.eq("name
HIBERNATE
HIBERNATE   What is difference between Jdbc and Hibernate
hibernate
hibernate  what is hibernate flow
hibernate
hibernate  what is hibernate listeners
Hibernate
Hibernate  how to use pagination concept in Hibernate
hibernate
hibernate  what is hibernate why we use
Hibernate
Hibernate  hibernate delete query execution
hibernate
hibernate  please give me the link where i can freely download hibernate software(with dependencies)   Learn hibernate, if you want to learn hibernate, please visit the following link: Hibernate Tutorials
hibernate
hibernate  how to uses optional column in hibernate
hibernate
hibernate   I want to learn how to use hibernate framework in web application . for storing database in our application
hibernate
hibernate   I want to learn how to use hibernate framework in web application . for storing database in our application
How to use AND OR operator in hibernate Detached criteria query?
How to use AND OR operator in hibernate Detached criteria query?  How to use AND OR operator in hibernate Detached criteria query?   You can use AND, OR operator in hibernate detachedCriteria through
hibernate
why hibernate?  why hibernate?   Hibernate: -Hibernate... library. It solves object-relational impedance mismatch problems. Hibernate makes the application development process easy Hibernate saves the development
Hibernate
Hibernate  Please tell me the difference between hibernate and jdbc
hibernate
hibernate  why we should use hibernate projection
hibernate
hibernate  pls give one simple example program for hibernate
Hibernate
Hibernate  How do you handle parent - child tables relationships in hibernate? How do you handle Detach state in hibernate
hibernate
hibernate  how to execute a sequence(in database) from Hibernate program or java program   Please visit the following link: Hibernate Tutorials
hibernate
hibernate  can any one one explain what is hibernate ?   Please visit the following link: Hibernate Tutorials
Hibernate
Hibernate  hello, how to run hibernate program in netbeans?please send me step by step instructions to run hibernate in netbeans
Hibernate - Hibernate
Hibernate Features  Hibernate features in eclipse
hibernate
hibernate  how to impot mysql database client jar file into eclipse for hibernate configuration   Hi Friend, Please visit the following link: http://www.roseindia.net/hibernate/runninge-xample.shtml Thanks
Hibernate
Hibernate  hi sir i need hibernate complete tutorial for download   Hi Friend, Please visit the following link: Hibernate Tutorials Thanks
hibernate
hibernate  hi what are the necessary jar files that we need to set in the classpath to execute a hibernate application
HIBERNATE
HIBERNATE  How u connects database using hibernate 3.0? Where you have written the database configuration details
hibernate
hibernate  How to know how many columns changed in a table when we are using hibernate
hibernate
hibernate  Is there any other way to call procedure in hibernate other than named query????? if we are using session object to get the connection then why hibernate we can directly call by using a simple java class??????? please
 

 

 

DMCA.com