John22_2
John22_2

Reputation: 123

Grails HQL vs SQL Statements

I would like an opinion about querying the database using HQL or SQL Statements, concerning simplicity, complexity and performance.

Upvotes: 3

Views: 962

Answers (1)

Timo Westkämper
Timo Westkämper

Reputation: 22200

With HQL you are operating on a class based domain level and with SQL on the relational model level. With HQL you can traverse your domain model in the queries and SQL you need to create the links with joins and join conditions which is more verbose.

Also the projections with HQL are simpler as you get directly objects out whereas with SQL you can tabular views of your relational data.

Optimizing HQL is more difficult as you need to operate on many levels (domain level, Hibernate, generated SQL, relational model), but mostly you can manage with less code.

SQL results are not typesafe, but this doesn't really matter as much in the Grails context as it would in a Java context.

Upvotes: 8

Related Questions