此内容没有您所选择的语言版本。

3.3. Mapping Queries


3.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 availabe Hibernate hints are
Expand
Table 3.2. Query hints
hintdescription
org.hibernate.cacheableWhether the query should interact with the second level cache (default to false)
org.hibernate.cacheRegionCache region name (default used otherwise)
org.hibernate.timeoutQuery timeout
org.hibernate.fetchSizeresultset fetch size
org.hibernate.flushModeFlush mode used for this query
org.hibernate.cacheModeCache mode used for this query
org.hibernate.readOnlyEntities loaded by this query should be in read only mode or not (default to false)
org.hibernate.commentQuery comment added to the generated SQL
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat