Will hql give you compile time errors like criteria query?
I remember hearing that one of the methods doesn't (besides raw SQL).
Will hql give you compile time errors like criteria query?
I remember hearing that one of the methods doesn't (besides raw SQL).
The short answer is no. Since HQL is essentially a string, you need an IDE to parse it and figure out if you're doing something wrong.
HQL wil not give you compile time errors, as it is only treated as a string at compile time. What do you mean with 'like criteria query'?
Criteria queries may not give you compile time errors, something like this will error
ICriteria crit = sess.CreateCriteria(typeof(Cat));
crit.SetMaxResults("50"); /* wrong parameter type */
List cats = crit.List();
Something like this will not
IList cats = sess.CreateCriteria(typeof(Cat))
.Add( Expression.Like("Naem", "Fritz%") ) /* misspelled property */
.Add( Expression.Between("Weight", minWeight, maxWeight) )
.List();
No query build in Hibernate, neither HQLs nor Critieras, will produce compile time errors. Nevertheless you can use the NamedQuery annotation to declare your static HQL queries in a static way. This will provide caching and validity checks when starting your application because hibernate's session factory will read all NamedQueries on first startup.