You can view the tutorials best in Google Chrome, Mozilla Firefox, Opera, higher version of Internet Explorer

Example On Hibernate Criteria Query

Hibernate » On Jul 12, 2011 By Sivateja

Let us see an example program on hibernate criteria query,
files required….

  • Product.java(POJO class)
  • Product.hbm.xml
  • hibernate.cfg.xml
  • ForOurLogic.java (For writing our business logic)

Product.java

Product.hbm.xml

hibernate.cfg.xml

ForOurLogic.java

Note:

  • In line number 25, created object of Criteria
  • In line number 26,  created Criterion interface object by using Restrictions class
  • In line number 27, added criterion interface object to criteria object
  • In line number 28,  executed criteria query by calling list() method in criteria
  • See line number 34, in this case we must typecast into our POJO class type only

Actually the internal concept is,  once we called the list() method in criteria (line number 28) all objects (records) will come and stores in list object, from there we used to take iterate then typecast into our POJO class type bla bla.






By [ Java/J2EE Developer & Web Designer ]
Founder of Java4s.com - Indian, lives in United States. You can contact me at sivateja [at] java4s.com
Follow me on


Comments

7 Responses to “Example On Hibernate Criteria Query”
  1. Mohit says:

    Dear Java4s Team,
    Can U explain the importance of
    @SuppressWarnings(“unchecked”) in ForOurLogic.java

  2. Java4s says:

    @Mohit

    Its nothing..!
    Eclipse used to show some warnings right.., with @SuppressWarnings() we can inform to the eclipse not to show any warnings. This is optional.

  3. k.venkatarao says:

    this is venkat. i am a java developer.very much thanq’s to java4s team. this web site like class room discussion.
    please send struts-hibernate projects .

    my mail id is : java24.code@gmail.com

  4. kishore says:

    Nice article… keep posting….

  5. balu says:

    hai to java4s team
    this site is helping a lot for me
    your articles are very good
    please send struts examples
    my mail id is: u.balu99@gmail.com

  6. Dilip says:

    Hi java4s,
    I Like This site very which is useful for freshers and experienced as well.
    In addition to the topics, Please add the advantages and disadvantages over the other things, performance etc., like, in this article why we should go for criteria other than HQL. which is good in performance. what to choose in a particular situation…

    Thanks in advance.

  7. Muthusamy says:

    This Java4s is very useful site for developers or java beginners. Having lot of information with detailed explanation.

    Thanks to java4s team! Keep up to add more contents.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
Sitemap :
spring Hibernate struts Json Ajax Log4j Log4j coreJava Servlets Web Services


Upcoming
  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
© 2010 - 2014 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.