"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Domain Classes/find.html" (14 Sep 2022, 62895 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

find

Purpose

Finds the first matching result for the given query or null if no instance is found

Examples

// Dan brown's first book
Book.find("from Book as b where b.author='Dan Brown'")

// with a positional parameter
Book.find("from Book as b where b.author=?", ['Dan Brown'])

// with a named parameter
Book.find("from Book as b where b.author=:author", [author: 'Dan Brown'])

// use the query cache
Book.find("from Book as b where b.author='Dan Brown'", [cache: true])
Book.find("from Book as b where b.author=:author",
          [author: 'Dan Brown'],
          [cache: true])

// query by example
def example = new Book(author: "Dan Brown")
Book.find(example)

// Using where criteria (since Grails 2.0)
Person p = Person.find { firstName == "Bart" }

Description

The find method allows querying with Hibernate’s query language HQL and querying by example. The basic syntax is:

Book.find(String query)
Book.find(String query, Collection positionalParams)
Book.find(String query, Collection positionalParams, Map queryParams)
Book.find(String query, Map namedParams)
Book.find(String query, Map namedParams, Map queryParams)
Book.find(Book example)
Book.find(Closure whereCriteria)

Parameters:

  • query - An HQL query

  • positionalParams - A List of parameters for a positional parametrized HQL query

  • namedParams - A Map of named parameters a HQL query

  • queryParams - A Map of query parameters. Currently, only cache is supported

  • example - An instance of the domain class for query by example