Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Implementing an EJB 3.0 Dynamic Query

Using EntityManager methods createQuery and createNativeQuery(String sqlString, Class resultType), you can create a Query object dynamically at runtime (see "Using Java").

Using the Query methods getResultList, getSingleResult, or executeUpdate you can execute the query (see "Executing a Query").

For more information, see:

Using Java

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 we use Query method getResultList.

Example 8-4 Implementing and Executing a Dynamic Query

Query queryEmployees = entityManager.createQuery(
    "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName = :firstname"
);

queryEmployeeByFirstName.setParameter("firstName", "Joan");

Collection employees = queryEmployees.getResultList();