Skip to main content
blob: 58160d38b82a1a58f2c4fef81c587ff807ec1e9c (plain) (tree)












<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
<!-- Run date = May 21, 2008 14:42:05 -->
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<title>Creating Named Queries</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 5.0" />
<meta name="date" content="2005-07-10T12:57:20+08:00" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Creating Named Queries" />
<meta name="relnum" content="Release 2.0" />
<meta name="copyright" content="Copyright (c) 2000, 2008 oracle . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at Contributors: Oracle - initial API and implementation" />
<link rel="copyright" href="dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="stylesheet" href="dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
<p><a id="BABIGBGG" name="BABIGBGG"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1>Creating Named Queries</h1>
<p><a id="sthref92" name="sthref92"></a><a id="sthref93" name="sthref93"></a>Named queries improve application performance because they are prepared once and they (and all of their associated supporting objects) can be efficiently reused thereafter, making them well suited for complex and frequently executed operations. Named queries use the JPA query language for portable execution on any underlying database; named native queries use the SQL language native to the underlying database.</p>
<p>Use this procedure to add <code>@NamedQuery</code> and <code>@NamedNativeQuery</code> annotations to the entity.</p>
<p>To create a named query:</p>
<ol start="1">
<p>Select the entity in the Package Explorer.</p>
<p>In the JPA Details view, expand Queries.</p>
<p>Click <span class="bold">Add</span> for a named query, or <span class="bold">Add Native</span> for a native query.</p>
<p>In the dialog that appears, enter the name of the query in the Name field and then click OK.</p>
<p>Enter the query in the Query field.</p>
<div class="figure"><a id="sthref94" name="sthref94"></a>
<p class="titleinfigure">Entering a Named Query</p>
<img src="img/task_entering_query.png" alt="The Queries section of the JPA Details view." title="The Queries section of the JPA Details view." /><br /></div>
<!-- class="figure" --></li>
<!-- class="sect1" -->
<!-- Start Footer -->
<div class="footer">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<td align="left" width="86%"><a href="dcommon/html/cpyr.htm"><span class="copyrightlogo">Copyright&nbsp;&copy;&nbsp;2006, 2008,&nbsp;Oracle.&nbsp;All&nbsp;rights&nbsp;reserved.</span></a></td>
<!-- class="footer" -->

Back to the top