Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Using Named Queries

Named queries improve application performance because they are prepared once and they (and all their associated supporting objects) can be efficiently reused thereafter making them well suited for frequently executed operations.

You can configure named queries at the session (see "Configuring Named Queries at the Session Level") or descriptor (see "Configuring Named Queries at the Descriptor Level") level.

For a session-level named query, you can execute the query using any of the following `Session` API calls:

- `executeQuery(String queryName)`

- `executeQuery(String queryName, arg1)`

- `executeQuery(String queryName, arg1, arg2)`

- `executeQuery(String queryName, arg1, arg2, arg3)`

- `executeQuery(String queryName, Vector args)`

Example 98-37 Executing a Session-Level Named Query

    Vector args = new Vector();
    args.add("Sarah");
    Employee sarah = (Employee)session.executeQuery(
        "employeeReadByFirstName",
        args
    );

For a descriptor-level named query, you can execute the query using any of the following `Session` API calls, as Example 98-38 shows:

- `executeQuery(String queryName, Class domainClass)`

- `executeQuery(String queryName, Class domainClass, arg1)`

- `executeQuery(String queryName, Class domainClass, arg1, arg2)`

- `executeQuery(String queryName, Class domainClass, arg1, arg2, arg3)`

- `executeQuery(String queryName, Class domainClass, Vector args)`

Example 98-38 Executing a Descriptor Level Named Query

    Vector args = new Vector();
    args.add("Sarah");
    Employee sarah = (Employee)session.executeQuery(
        "ReadByFirstName",
        Employee.class,
        args
    );

For more information, see "Named Queries"