Specifying Queries
Use the Queries tab to specify TopLink Expressions, EJB QL queries, and SQL queries to access the database. EJB QL is a declarative language that presents queries from an object-model perspective. Refer to the EJB specification for detailed information.
For 2.0 CMP projects, the ejb-jar.xml file stores query lists. You can define the queries in the file and then read them into the TopLink Mapping editor, or define them on the Queries tab and write them to the file.
To create queries:
- In the Structure window, select a descriptor.
- Click the Named Queries tab in the Mapping editor.
- The Queries tab contains the following additional tabs:
- Select the appropriate tab:
Custom SQL Queries
Use this procedure to create custom SQL queries for the TopLink descriptor.
To create custom SQL queries:
- In the Application Navigator, select a descriptor.
- Click the Queries tab in the Editor pane.
- Click the Custom SQL tab.
- Click appropriate SQL function tab on the Custom SQL Queries tab to type your own query object or SQL string to control these actions for a descriptor.
Note: The TopLink Mapping editor does not validate the SQL code that you enter. The code is defined by the specific database type.
To control the five custom query tabs, you can include your own query object or SQL string for a particular descriptor. The SQL string for each database is defined by the type of database.
For example, the stored procedure to read an object may use the following string:
- Read_Employee(EMP_ID=>4653)
The query manager requires the following string to read the object:
- Read_Employee(EMP_ID=>#EMP_ID)
Named Queries
Use named queries to specify SQL, EJB QL, or TopLink Expression queries to access the database.
To create a named query:
- In the Application Navigator, select a descriptor.
- Click the Queries tab in the Editor pane.
- Click the Named Queries tab in the Queries tab.
- Click Add to create a new query. The Add Named Query dialog appears.
- To delete an existing query, select the query and click Remove. To rename an existing query, select the query and click Rename.
- Select the query type (for EJB descriptors), enter the query name, and click OK.
- The Named Queries tab contains the following additional tabs:
- Click on the Named Queries - General tab to specify the query type and parameters.
- Select the query type and Add or Remove parameters for the query.
- Click the Named Queries - Format tab to specify the named query and its format.
- Click on the Named Queries - Options tab to specify additional options for the named query.
Note: These options are not available for findOneByQuery and findManyByQuery.
- Click Advanced to specify additional named query options.
- Use the Advanced Query Options dialog to specify additional query options.
- Click OK.
Related Topics
About TopLink Descriptors
Building Expressions
Working with Descriptors
Working with Descriptor Properties
Mapping Descriptors
Copyright © 1997, 2004, Oracle.
All rights reserved.