Skip Headers

# Executing Queries

Previous

Next

In TopLink, you execute most queries using the `Session` API summarized in Table: Session Methods for Executing a Query.

Session Methods for Executing a Query

Query Type | Session Method | Advantages and Disadvantages
--- | --- | ---
Session Queries | `readObject` `readAllObjects` `writeObject` `writeAllObjects` `deleteObject` `deleteAllObjects` `insertObject` `updateObject` | Advantages: the most convenient way to perform common data source operations on objects. Disadvantages: less control over query execution and results; less efficient for frequently executed queries.
Database Queries Named Queries Redirect Queries | `executeQuery` | Advantages: greatest configuration and execution flexibility; can take advantage of named queries for efficiency. Disadvantages: you must explicitly create and configure `DatabaseQuery` and possibly `Call` objects.
Call Queries | `executeSelectingCall` `executeNonSelectingCall` | Advantages: convenient way to directly apply an action to unmapped data. Disadvantages: least control over query execution and results; your application must do more work to handle raw data results.

Note:

Oracle recommends that you perform all data source operations using a unit of work: doing so is the most efficient way to manage transactions, concurrency, and referential constraints. For more information, see "Understanding TopLink Transactions".

Alternatively, you can execute queries outside of a unit of work using a session API directly, but doing so places greater responsibility on your application to manage transactions, concurrency, and referential constraints.

TopLink executes `DescriptorQueryManager` queries when you execute a session query. For more information, see "Descriptor Query Manager Queries".

You execute EJB finders when you call the appropriate finder method on an EJB. For more information, see "EJB Finders".

WARNING: Allowing an unverified SQL string to be passed into methods (for example: `setSQLString(String sql), readAllObjects(Class class, String sql)` methods) makes your application vulnerable to SQL injection attacks.

For more information, see the following:

- "Using Basic Query API"

- "Using Advanced Query API"