Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/StoredProcedures"

Line 14: Line 14:
  
 
Any CRUD or mapping operation can also be overridden using a stored procedure call using a DescriptorCustomizer and the DescriptorQueryManager API.
 
Any CRUD or mapping operation can also be overridden using a stored procedure call using a DescriptorCustomizer and the DescriptorQueryManager API.
 +
 +
See,
 +
* [http://wiki.eclipse.org/Using_Basic_Query_API_%28ELUG%29#Using_a_StoredProcedureCall User Guide:Using a StoredProcedureCall]
  
 
=== Oracle stored procedure using OUT CURSOR ===
 
=== Oracle stored procedure using OUT CURSOR ===
 
<source lang="sql">
 
<source lang="sql">
 +
CREATE PROCEDURE EMP_READ_ALL
 
</source>
 
</source>
  
Line 27: Line 31:
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class);
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class);
 
StoredProcedureCall call = new StoredProcedureCall();
 
StoredProcedureCall call = new StoredProcedureCall();
 +
call .setProcedureName("EMP_READ_ALL");
 +
call .useNamedCursorOutputAsResultSet("RESULT_SET");
 
databaseQuery.setCall(call);
 
databaseQuery.setCall(call);
  

Revision as of 10:23, 1 February 2011


EclipseLink has extended support for stored procedure execution including:

A stored procedure call be used in any query to read objects, or read or modify raw data.

Any CRUD or mapping operation can also be overridden using a stored procedure call using a DescriptorCustomizer and the DescriptorQueryManager API.

See,

Oracle stored procedure using OUT CURSOR

CREATE PROCEDURE EMP_READ_ALL

Using JpaEntityManager createQuery() API to execute a stored procedure

import javax.persistence.Query;
import org.eclipse.persistence.queries.StoredProcedureCall;
import org.eclipse.persistence.queries.ReadAllQuery;
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class);
StoredProcedureCall call = new StoredProcedureCall();
call .setProcedureName("EMP_READ_ALL");
call .useNamedCursorOutputAsResultSet("RESULT_SET");
databaseQuery.setCall(call);
 
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(databaseQuery);
List<Employee> result = query.getResultList();

Using @NamedStoredProcedureQuery to define a stored procedure

@NamedStoredProcedureQuery
@Entity
public class Employee {
 ...
}