Hibernate Projections
In this section, you will learn about the hibernate projections with an appropriate example.Projections: The package Criteria is used as a framework by the applications just to build the new kinds of projection. may be used by applications as a framework for building new kinds of Projection. In general Projection means to retrieve while in case of SQL Projection means "Select" clause. Most of the applications uses the built-in projection types by means of the static factory methods of this class.
Product.java
package net.roseindia; |
Criteria API: enables us to specify criteria based on various.
In the class projectionExample.java, first we create the session object with the help of the SessionFactory interface. Then we use the createQuery() method of the Session object which returns a Query object. Now we use the openSession() method of the SessionFactory interface simply to instantiate the Session object.
Then we obtain the criteria object simply by invoking the createCriteria() method of the Session's object. Now we create a projectionList object add the fields having properties "name" and "price". Set it to the Criteria object by invoking the setProjection() method and passing the projectList object into this method and then add this object into the List interface's list object and iterate this object list object to display the data contained in this object.
projectionExample.java
package net.roseindia; |
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).log4j:WARN Please initialize the log4j system properly.Hibernate: select this_.name as y0_, this_.price as y1_ from Product this_ Product Name PriceComputer 23000.0 Mobile 15000.0 Laptop 200.0 Keyboard 1500.0 PenDrive 200.0HardDisk 2500.0 Computer 100.0 |
No comments:
Post a Comment