Could you explain query interface with simple code

Posted on 2011-10-20
Last Modified: 2013-11-24
ould you explain query interface with simple code in Hibernate
Question by:stmani2005
    1 Comment
    LVL 4

    Accepted Solution

    The Criteria interface allows to create and execute object-oriented queries. It is powerful alternative to the HQL but has own limitations. Criteria Query is used mostly in case of multi criteria search screens, where HQL is not very effective.

    The interface org.hibernate.Criteria is used to create the criterion for the search. The org.hibernate.Criteria interface represents a query against a persistent class. The Session is a factory for Criteria instances. Here is a simple example of Hibernate Criterial Query:

    package roseindia.tutorial.hibernate;

    import org.hibernate.Session;
    import org.hibernate.*;
    import org.hibernate.cfg.*;
    import java.util.*;
     * @author Deepak Kumar
    Hibernate Criteria Query Example
     */public class HibernateCriteriaQueryExample {
      public static void main(String[] args) {
      Session session = null;
      try {
      // This step will read
    hibernate.cfg.xml and prepare hibernate for
      // use
    sessionFactory = new Configuration().configure()
      session =
      //Criteria Query Example
      Criteria crit =
      List insurances =
      for(Iterator it =
      Insurance insurance =
    ID: " + insurance.getLngInsuranceId());
    Name: " + insurance.getInsuranceName());
      } catch (Exception e) {
      } finally {

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    maxMirror challenge 10 68
    java constructor error 8 63
    scoresIncreasing challenge 10 47
    scoresClump  challenge 31 85
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now