Named Queries

Most often queries are predefined and stored on the Entity Manager. This allows for queries to be defined ahead of time, recalled and used at runtime. This is done by storing the query on the entity bean using annotations.

Creating a query with parameters

Defining parameters on your query allows for the reuse of a query to return different results. Parameters (prefixed in JPQL strings by semicolons) require values. If query uses parameters (prefixed in JPQL strings by semicolons) then values for them passed through setParameter method. Changing the example above to use parameters would look like:

Query Hints

Setting a 'hint' on the query can alter implementation specific query behaviour. This allows for queries to be setup with vendor specific configuarations that are not available in the JPA specification.

The following OC4J-specific hint forces refreshing of the objects already read.