Beginner |
![Beginner Beginner](./images/ranks/beginner.gif) |
Joined: Wed Jul 25, 2007 6:32 am Posts: 22
|
You can use either Criteria or HQL (Named Queries)
HQL is powerfull with advanced features and usefull for more difficult problems.
Criteria allows you to built a query at runtime. But criteria are often less readable then HQL but are validated at compile time.
A Criteria is a tree of Criterion instances. (Restrictions return criterion instances).
For example:
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.like("firstname", "Scott"); //add a criterion
List result = criteria.list();
firstname is the java property in the User Class and "Scott" is its value.
|
|