////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
[[querying]]
== Querying

GORM provides multiple querying mechanisms, ranging from simple dynamic finders to full SQL queries.

* xref:querying-finders[Dynamic Finders] — auto-generated methods based on properties
* xref:querying-whereQueries[Where Queries] — type-safe Groovy criteria DSL
* xref:querying-criteria[Criteria Queries] — advanced query builder with Hibernate 7 DSL
* xref:querying-detachedCriteria[Detached Criteria] — reusable query fragments and subqueries
* xref:querying-hql[HQL Queries] — Hibernate Query Language
* xref:querying-nativeSql[Native SQL Queries] — raw database SQL via Hibernate

=== Dynamic Finders

The simplest form of querying uses auto-generated finder methods based on property names:

[source,groovy]
----
Book.findByTitle('Groovy in Action')
Book.findAllByAuthorAndGenre('Dierk König', 'Tech')
Book.countByGenre('Fiction')
Book.findByTitleLike('%Groovy%')
Book.findAllByPagesGreaterThan(300)
Book.findAllByTitleIlike('%groovy%')    // case-insensitive
----

Finder methods support pagination:

[source,groovy]
----
Book.findAllByGenre('Fiction', [max: 10, offset: 0, sort: 'title', order: 'asc'])
----

=== `get`, `list`, `count`

[source,groovy]
----
Book.get(1)                                 // by id
Book.list()                                 // all
Book.list(max: 10, offset: 20)             // paginated
Book.count()                                // total count
----
