October 2006
Intermediate to advanced
880 pages
22h 11m
English
Let's start with a few examples so you understand the basic usage. In earlier chapters, we mentioned that there are three ways to express queries in Hibernate:
Hibernate Query Language (HQL), and the subset standardized as JPA QL:
session.createQuery("from Category c where c.name like 'Laptop%'");
entityManager.createQuery(
"select c from Category c where c.name like 'Laptop%'"
);
Criteria API for query by criteria (QBC) and query by example (QBE):
session.createCriteria(Category.class)
.add( Restrictions.like("name", "Laptop%") );
Direct SQL with or without automatic mapping of resultsets to objects:
session.createSQLQuery( "select {c.*} from CATEGORY {c} where NAME like 'Laptop%'" ).addEntity("c", Category.class); ...