The Hibernate Query Language

Hibernate does not use SQL for its statements. It uses its own query language called Hibernate Query Language (HQL), which is very similar to SQL. Because HQL is so similar to SQL, it takes almost no time to learn and makes the internals of the framework a bit easier to work with.

HQL is fully covered in Hibernate documentation; but we are going to discuss just a few major points here. First of all, HQL is case-sensitive. Unlike in SQL, the column names (bean properties) as well as table names (object names) are case sensitive. This is because HQL uses object names rather than table names to select the data. When you are writing an HQL statement, you do not actually have to worry about which tables are going to be used to build the result—it is up to Hibernate to find which tables map to which classes and issue the select statement to the database.

HQL is also an object-oriented language because it must include support for polymorphism. You will see from the examples in the rest of the chapter that other parts of the language, such as where, order by, group by, having, and many other clauses, are almost exactly the same as their SQL counterparts.

Possibly the most difficult part of the language that you have to get used to is that you select data from classes that are mapped in the mapping files. Rather than writing select * from Test to select all the rows from table Test, you have to write select t from Test as t. In this case, however, Test is a reference to the Test domain object, not the Test table.



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net