[Prev] Thread [Next]  |  [Prev] Date [Next]

[Hibernate] Native SQL documentation question Petri Rautakoski Fri Nov 14 03:00:48 2008

I have been reading Hibernate Core documentation and section 16.1.4 has a
little tutorial for multiple entities query:

String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +

         "BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*} " +
         "FROM CAT_LOG c, CAT_LOG m WHERE {c.mother} = c.ID";

List loggedCats = sess.createSQLQuery(sql)
        .addEntity("cat", Cat.class)

        .addEntity("mother", Cat.class).list()

1. ${c.mother} = c.id makes a relation from cat to itself as a mother of
itself, is this correct?
2. ${c.XXX} as shorthands are with different alias than entity related to
query: addEntity("cat", Cat.class), does Hibernate make a entity relation to
FROM part with order of adding with addEntity? In otherwords:
    CAT_LOG c -> cat as cat is the alias in the first addEntity call
    CAT_LOG m -> mother as mother is the alias in the second addEntity call
3. how does Hibernate resolve the selected columns: ID as {c.id}, NAME as {
c.name}, BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*}, in
some columns is c alias and then there is mother.* for the rest, but how
this c is related to cat alias? This is totally related to second question.
4. In ID as {c.id} {c.id} means the mapped property in Cat.class, but from
which table ID is retrieved, it doesn't have alias listed in FROM part (c or
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
hibernate-devel mailing list