Use HQL when you know the exact shape of the query. For example, if you were implementing a method like "findPersistedObjectByDate(Date d);".
Use normal Criteria when you don't know the exact shape of the query. For example, when your query is being built from user-entered values, where some values are optional.
Use query-by-example Criteria as a shortcut for normal Criteria when you have a similar object. It's also useful if your query is simple but you don't have access to hibernate classes in the place you're building the query. For example, in a webapp action class, you mightn't be allowed (because of company policy) to use hibernate DetachedCriteria. So you could build an object with the user-entered search criteria, and pass that down through your business logic to your data access layer, and that does the search by example.
_________________ Code tags are your friend. Know them and use them.
|