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

Hibernate Projections Introduction

Hibernate » On Jul 13, 2011 1 Comment

So far in criteria, we are able to load complete object right….! let us see how to load the partial objects while working with criteria.  The projections concept is introduced in hibernate 3.0 and mainly we can do the following 2 operations using the projection

  • We can load partial object from the database
  • We can find the Result of Aggregate functions

Projection is an Interface given in “org.hibernate.criterion” package, Projections is an class given in same package,  actually Projection is an interface, and Projections is an class and is a factory for producing projection objects.

In Projections class, we have all static methods and each method of this class returns Projection interface object.

If we want to add a Projection object to Criteria then we need to call a method setProjection()

Remember, while adding projection object to criteria, it is possible to add one object at a time.  It means if we add 2nd projection object then this 2nd one will overrides the first one (first one wont be work), so at a time we can only one projection object to criteria object.

Using criteria, if we want to load partial object from the database, then we need to create a projection object for property that is to be loaded from the database


If we add multiple projections to criteria then the last projection added will be considered to execute see…


Here collections list l, is going to contain the price in the form of Double objects, but product names are over ridden,  second projection over rides the first one, i mean p2 only will works p1 will not works, actually there is a way to add multiple projections to criteria to select more than one column from the database i will tell you in the next example :-)


What you are thinkig....

One Response to “Hibernate Projections Introduction”
  1. sankar says:

    Excellent information

If you want a pic to show with your comment, go get a gravatar !
Please post your questions on Java4s Answers forum

Ask a Question ?

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
Tutorials Online :
spring Hibernate struts Json Ajax Log4j Log4j
coreJava Servlets

UpComing :
Jsps,Web Services
Java4s is optimized for learning java technologies, all the examples in this site are constantly reviewed to avoid errors. While using this site you agree to have read and accepted our terms of use and privacy policy
Especially i have prepared this blog by keeping fresher's in mind, however it will be very useful for real time developers too.

© 2014 Java4s All rights reserved. | strPro4Tut v(2.0) Theme designed by Team Java4s.