HIBERNATE / NOTES</>↗Hibernate26 Oct 2008
The code below demonstration the use of Projections.min(), Projections.max(), Projections.avg() and Projections.sum(). package org.kodejava.hibernate; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.HibernateException; import org.hibernate.Criteria; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Projections; import org.kodejava.hibernate.model.Track; public class MinMaxAvgSumProjectionsDemo { public static Sessio...
HIBERNATE / NOTES</>↗Hibernate25 Oct 2008
The Criteria.uniqueResult() method make it easier to query a single instance of a persistence object. When no persistence found this method will return a null value. package org.kodejava.hibernate; import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Restrictions; import org.kodejava.hibernate.model.Genre; public class Un...
HIBERNATE / NOTES</>↗Hibernate21 Oct 2008
o set the fetching mode for association we can call the Criteria‘s setFetchMode() method. We can use the FetchMode.SELECT or FetchMode.JOIN. package org.kodejava.hibernate; import org.hibernate.*; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Restrictions; import org.kodejava.hibernate.model.Record; import java.util.List; public class FetchModeDemo { public static Session getSession() throws HibernateException { String cfg = "hibernate.cfg.xml"; Sessi...
HIBERNATE / NOTES</>↗Hibernate20 Oct 2008
The example below show how to get total row count using the Projections.rowCount(). The result of this query will be a single object of Integer that contains the result of executing an SQL select count (*) command. package org.kodejava.hibernate; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.HibernateException; import org.hibernate.Criteria; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Projections; import org...
HIBERNATE / NOTES</>↗Hibernate17 Oct 2008
In this demo you’ll see how to order the result set of out Criteria query. It can be done by adding the org.hibernate.criterion.Order into the Criteria object, and we can either order the result in ascending or descending order. package org.kodejava.hibernate; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.HibernateException; import org.hibernate.Criteria; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Order; im...
HIBERNATE / NOTES</>↗Hibernate15 Oct 2008
In this example you’ll learn how to add restrictions to the Criteria object. Using restriction we can narrow the result of our query. In the code below we add some restrictions such as Restrictions.eq(), Restrictions.like() and Restrictions.isNotNull(). In Hibernate framework you’ll find a lot of class the use a method chaining. As in the example […]