Meaningless Drivel is fun!
The moose likes Object Relational Mapping and the fly likes Q 4 C. Bauer & G. King (2): Hibernate & formulating queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Q 4 C. Bauer & G. King (2): Hibernate & formulating queries" Watch "Q 4 C. Bauer & G. King (2): Hibernate & formulating queries" New topic

Q 4 C. Bauer & G. King (2): Hibernate & formulating queries

Gian Franco
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Dear authors,

In the old days I was used to formulate my
queries to the database in SQL.

In the new days this has basically remained
the same, an SQL query is formulated, although,
in the Java application I'm working on, this
is done in a rather complicated way (it's the
fault of the previous programmers )

What does Hibernate fundamentally change
in the way a query is posed in order to
retrieve data?


Gian Franco Casula
[ August 31, 2004: Message edited by: Gian Franco Casula ]

"Eppur si muove!"
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
One of ORMs targets is to degravate the programmer from writting pure SQL. It translates the relational model querying (SQL) in object model querying.
For example:
Person contains and Address entity and Person is mapped to table PERSON_TBL.
Having to select address street we write:
select person.address.street from Person person.

blog -
Christian Bauer
Ranch Hand

Joined: Aug 31, 2004
Posts: 45
First, it is important to mention that Hibernate doesn't take away the SQL. You can execute a native SQL query and have Hibernate mapping the result set to an object graph automatically or get a direct JDBC connection in rare cases. More features to this functionality have been in added in Hibernate3, you may now rewrite any SQL statement Hibernate uses to load, store, delete, and update objects. See Gavin's recent blog entry for more information:

In addition to hand-written SQL, Hibernate offers you several ways to retrieve your objects:

1. You simply "walk" the object graph and Hibernate loads associated instances for you
2. You execute an HQL query; HQL is an object-oriented extension of SQL (EJB3-QL will be similar)
3. You execute a Criteria and/or Example query, both ways are object-oriented typesafe ways to build a query, especially useful for dynamic query generation
4. You load/get an object by knowing and providing its identifier value (primary key...)

The HQL and Criteria/Example query features are powerful, and will be extended significantly in the Hibernate3 timeline.

Co-Author of <a href="" target="_blank" rel="nofollow">Hibernate in Action</a>
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Hi Christian,

How is Hibernate Query Language different from JDO QL?

Thanks a lot!

Gavin King
Ranch Hand

Joined: Aug 31, 2004
Posts: 76
Hibernate's query language is designed to be a "minimal" object-oriented extension to SQL. The idea is that it is very easy to learn HQL if you already know SQL, and that it is very easy to predict the shape of the SQL that results from a HQL query. Also, because HQL is SQL-like, it is also "SQL-friendly" - you can do stuff like calling SQL functions, even user written ones with no "conceptual gap".

That is the first difference.

The second difference is that Hibernate unifies the notion of "querying", with the notion of "association fetching", which are regarded as different things by existing JDO implementations and by the JDO2 spec. We believe that this is an extremely unnatural split, and that the two things are really two parts of the same thing.

The third difference is that the mature implementation of HQL (Hibernate 2.0 and above) is much, much more feature rich than JDOQL in JDO 1.x. JDO2 has added many new features.

Co-Author of <a href="" target="_blank" rel="nofollow">Hibernate in Action</a>
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312


Java Developer, Thailand
I agree. Here's the link:
subject: Q 4 C. Bauer & G. King (2): Hibernate & formulating queries
It's not a secret anymore!