Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
Using EntityManager
methods createQuery
or createNativeQuery
, you can create a Query
object dynamically at run time (see "Using Java"). Using the Query
methods getResultList
, getSingleResult
, or executeUpdate
you can execute the query (see "Executing a Query").
Optionally, you can configure your named query with query hints to use JPA persistence provider vendor extensions (see "Configuring TopLink Query Hints in a JPA Query").
For more information, see the following:
"Creating a Dynamic Java Persistence Query Language Query With the Entity Manager"
"Creating a Dynamic TopLink Expression Query With the EntityManager"
"Creating a Dynamic Native SQL Query With the EntityManager"
Example 8-4 shows how to create a dynamic EJB QL query with parameters and how to execute the query. In this example, the query returns multiple results so Query
method getResultList
is used.
Example 8-4 Implementing and Executing a Dynamic Query
Query queryEmployeeByFirstName = entityManager.createQuery( "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName = :firstname" ); queryEmployeeByFirstName.setParameter("firstName", "Joan"); Collection employees = queryEmployeeByFirstName.getResultList();