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 ]
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 PTBL.street from PERSON_TBL PTBL in SQL, but select person.address.street from Person person.
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: http://blog.hibernate.org/cgi-bin/blosxom.cgi/Gavin%20King/customsql.html
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="http://www.manning.com/bauer" target="_blank" rel="nofollow">Hibernate in Action</a>
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="http://www.amazon.com/exec/obidos/ASIN/193239415X/ref=jranch-20" target="_blank" rel="nofollow">Hibernate in Action</a>