Este conteúdo não está disponível no idioma selecionado.

2.3. Mapping Queries


2.3.Mapping JPAQL/HQL queries. Mapping JPAQL/HQL queries

You can map EJBQL/HQL queries using annotations. @NamedQuery and @NamedQueries can be defined at the class level or in a JPA XML file. However their definitions are global to the session factory/entity manager factory scope. A named query is defined by its name and the actual query string.
<entity-mappings>
    <named-query name="plane.getAll">
        <query>select p from Plane p</query>
    </named-query>
    ...
</entity-mappings>
...

@Entity
@NamedQuery(name="night.moreRecentThan", query="select n from Night n where n.date >= :date")
public class Night {
    ...
}

public class MyDao {
    doStuff() {
        Query q = s.getNamedQuery("night.moreRecentThan");
        q.setDate( "date", aMonthAgo );
        List results = q.list();
        ...
    }
    ...
}
Copy to Clipboard Toggle word wrap
You can also provide some hints to a query through an array of QueryHint through a hints attribute.
The available Hibernate hints are
Expand
Table 2.2. Query hints
hint description
org.hibernate.cacheable Whether the query should interact with the second level cache (default to false)
org.hibernate.cacheRegion Cache region name (default used otherwise)
org.hibernate.timeout Query timeout
org.hibernate.fetchSize resultset fetch size
org.hibernate.flushMode Flush mode used for this query
org.hibernate.cacheMode Cache mode used for this query
org.hibernate.readOnly Entities loaded by this query should be in read only mode or not (default to false)
org.hibernate.comment Query comment added to the generated SQL
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat