1 Reply Latest reply on Jul 1, 2009 10:33 PM by asookazian

    How to write join in HQL

      Hello,
      I am trying to create a query in HQL but I don't know how to do it. I want to use the clause inner join, I looked for in internet but I don't found nothing.


      Can anybody tell me how create a query using inner join clause?


      I want to do something like this:
      select * from usuario inner join contacto on usuario.id=contacto.id


      Regards.

        • 1. Re: How to write join in HQL
          asookazian

          http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html#queryhql-joins


          from Cat as cat
              inner join cat.mate as mate



          the getMate() method will be called to return 1 (or many?) mates for the cats.


          I don't like these goofy Cat examples in the HQL docs.


          It's easier to think about this with a real-world example like Customer and Order entities.


          So imagine there is a 1:m relationship between Customer and Order entities.  The following query returns all Order entities that have 'Johnson' as the customer's last name.


          select o 
          from Order o 
          inner join o.customer c
          where c.lastName = 'Johnson'



          Read JPA/Hibernate book for more info.