|  | <html><head> | 
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|  | <title>6.  Query Factory</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.2 User's Guide"><link rel="up" href="jpa_overview_em.html" title="Chapter 8.  EntityManager"><link rel="prev" href="jpa_overview_em_cache.html" title="5.  Cache Management"><link rel="next" href="jpa_overview_em_locking.html" title="7.  Entity Locking"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.  | 
|  | Query Factory | 
|  | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_em_cache.html">Prev</a> </td><th width="60%" align="center">Chapter 8.  | 
|  | EntityManager | 
|  | </th><td width="20%" align="right"> <a accesskey="n" href="jpa_overview_em_locking.html">Next</a></td></tr></table><hr></div><div class="section" title="6.  Query Factory"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_em_query">6.  | 
|  | Query Factory | 
|  | </h2></div></div></div> | 
|  |  | 
|  | <a class="indexterm" name="d5e2672"></a> | 
|  | <a class="indexterm" name="d5e2676"></a> | 
|  | <pre class="programlisting"> | 
|  | public Query createQuery(String query); | 
|  | </pre> | 
|  | <p> | 
|  | <code class="classname">Query</code> objects are used to find entities matching certain | 
|  | criteria. The <code class="methodname">createQuery</code> method creates a query using | 
|  | the given Java Persistence Query Language (JPQL) string. See | 
|  | <a class="xref" href="jpa_overview_query.html" title="Chapter 10.  JPA Query">Chapter 10, <i> | 
|  | JPA Query | 
|  | </i></a> for details. | 
|  | </p> | 
|  | <pre class="programlisting"> | 
|  | public Query createNamedQuery(String name); | 
|  | </pre> | 
|  | <p> | 
|  | This method retrieves a query defined in metadata by name. The returned | 
|  | <code class="classname">Query</code> instance is initialized with the information | 
|  | declared in metadata. For more information on named queries, read | 
|  | <a class="xref" href="jpa_overview_query.html#jpa_overview_query_named" title="1.11.  Named Queries">Section 1.11, “ | 
|  | Named Queries | 
|  | ”</a>. | 
|  | </p> | 
|  | <pre class="programlisting"> | 
|  | public Query createNativeQuery(String sql); | 
|  | public Query createNativeQuery(String sql, Class resultCls); | 
|  | public Query createNativeQuery(String sql, String resultMapping); | 
|  | </pre> | 
|  | <p> | 
|  | <span class="emphasis"><em>Native</em></span> queries are queries in the datastore's native | 
|  | language. For relational databases, this is the Structured Query Language (SQL). | 
|  | <a class="xref" href="jpa_overview_sqlquery.html" title="Chapter 12.  SQL Queries">Chapter 12, <i> | 
|  | SQL Queries | 
|  | </i></a> elaborates on JPA's | 
|  | native query support. | 
|  | </p> | 
|  | </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jpa_overview_em_cache.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_em.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jpa_overview_em_locking.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.  | 
|  | Cache Management | 
|  |  </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 7.  | 
|  | Entity Locking | 
|  | </td></tr></table></div></body></html> |