////
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.
////


== findBy*



=== Purpose


Dynamic method that uses the properties of the domain class to execute a query returning the first matching result.


=== Examples


Given the domain class `Book`:

[source,groovy]
----
class Book {
    String title
    Date releaseDate
    String author
    Boolean paperback
}
----

The following are all possible:

[source,groovy]
----
def b = Book.findByTitle("The Shining")
b = Book.findByTitleAndAuthor("The Sum of All Fears", "Tom Clancy")
b = Book.findByReleaseDateBetween(firstDate, new Date())
b = Book.findByReleaseDateGreaterThanEquals(firstDate)
b = Book.findByReleaseDateLessThanEquals(firstDate)
b = Book.findByTitleLike("%Hobbit%")
b = Book.findByTitleIlike("%Hobbit%") // ignores case
b = Book.findByTitleNotEqual("Harry Potter")
b = Book.findByReleaseDateIsNull()
b = Book.findByReleaseDateIsNotNull()
b = Book.findPaperbackByAuthor("Douglas Adams")
b = Book.findNotPaperbackByAuthor("Douglas Adams")
b = Book.findByAuthorInList(["Douglas Adams", "Hunter S. Thompson"])
----


=== Description


GORM supports the notion of  link:{hibernate5GuideFromRef}index.html#finders[Dynamic Finders]. The `findBy*` method finds the first result for the given method expression.

The following operator names can be used within the respective dynamic methods:

* `LessThan`
* `LessThanEquals`
* `GreaterThan`
* `GreaterThanEquals`
* `Between`
* `Like`
* `Ilike` (i.e. ignorecase like)
* `IsNotNull`
* `IsNull`
* `Not`
* `NotEqual`
* `And`
* `Or`
* `InList`

The above operator names can be considered keywords, and you will run into problems when querying domain classes that have one of these names used as property names. For more information on  link:{hibernate5GuideFromRef}index.html#finders[dynamic finders] refer to the user guide.
