The use of join in Grails GORM queries

≡放荡痞女 提交于 2019-12-11 02:38:35

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6707438/the-use-of-join-in-grails-gorm-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!