rjc
rjc

Reputation: 2915

The use of join in Grails GORM queries

In Grails we define domain classes in such a way that clearly indicates the relationship between domain classes such as one to many or belongsTo (if any). Since Grails is based on DRY, does that mean we do not need to use the join keyword when performing complex HQL queries in Grails DomainClass.ExecuteQuery method?

Upvotes: 2

Views: 7771

Answers (2)

Burt Beckwith
Burt Beckwith

Reputation: 75681

In general no, you don't need explicit joins because Hibernate knows about the relationships of the tables based on the relationships of the domain classes. One exception is collections, and it is possible to use joins to customize the default behavior. The best resource on HQL is the Hibernate documentation itself: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

Upvotes: 1

Michael J. Lee
Michael J. Lee

Reputation: 12416

Grails doesn't change the way you write your HQL it is the same whether your using Grails domain classes or POJO's. If you need to write queries that navigate the object graph then you need to use the same syntax as you would with HQL like FROM parent p JOIN p.child c WHERE c.age = 10. Criteria queries work in the same way but you just get to use closures.

Take a look at the documentation (section 5.4.3) for more information.

Upvotes: 3

Related Questions