Creating Named Queries

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.

Use this procedure to add @NamedQuery and @NamedNativeQuery annotations to the entity.

To create a named query:

  1. Select the entity in the Package Explorer.

  2. In the JPA Details view, expand Queries.

  3. Click Add for a named query, or Add Native for a native query.

  4. In the dialog that appears, enter the name of the query in the Name field and then click OK.

  5. Enter the query in the Query field.

    Entering a Named Query

    The Queries section of the JPA Details view.