Skip to content

Getting started

gert-wijns edited this page Feb 4, 2014 · 3 revisions

Obtaining a TypeSafeQuery

To obtain a query, call the createQuery() method on a TypeSafeQueryHelper.

TypeSafeQueryHelper helper = new TypeSafeQueryHelperImpl(sessionFactory); // probably injected
TypeSafeRootQuery query = helper.createQuery();

Querying an entity

To query an entity, simply call the from(Class<?> entityClass) method on a TypeSafeRootQuery instance. This will return a proxy of the entityClass to continue building the query.

Person person = query.from(Person.class); // would select people

Converting the query object to hql

To convert a query object to hql, call the toHqlQuery() method on the query.

HqlQuery hqlQuery = query.toHqlQuery(); // would convert the query to hql

hqlQuery.getHql() would yield => 
" from Person hobj1"

Next: How to join entities

Clone this wiki locally