Hibernate Queries - I
2 May 2008Hibernate is a popular OR (Object Relational) mapping framework. To access database, we have to use Hibernate Query language. I will present the basics in this post that will help you starting quering database tables using HQL.
Hibernate queries can be roughly divided into 3 categories:
The queries we general use can be divided up into three main categories :
- Queries using one class
- Queries which several classes so join operation is required
- Queries which cannot be efficiently done using joins
Lets take an example of simplest HQL query:
from Sale sale where sale.date > :startDateLet me present a query with join operation:
from Cat as cat inner join cat.mate as mate left outer join cat.kittens as kitten
A little tricky example follows:
from Cat as cat
inner join fetch cat.mate
left join fetch cat.kittens child
left join fetch child.kittensConsider the following (simplified) Hibernate mappings:
<class name="Sale" dynamic-update="true" table="t_sale" > <id column="sale_ch_id" name="id" unsaved-value="null" type="string"> <generator class="uuid.hex"/> </id> <property column="sale_d_date" name="date" type="date" not-null="true"/> <property column="sale_n_price" name="price" type="big_decimal" not-null="true"/> <many-to-one name="product" class="Product" column="prod_ch_id".../> ... </class>
continued …
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Hibernate Queries - I