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

From Eclipsepedia

Jump to: navigation, search
Line 5: Line 5:
 
* CURSOR output parameter support
 
* CURSOR output parameter support
 
* Result set support
 
* Result set support
* Annotation support using @NamedStoredProcedureQuery  
+
* Annotation support using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/annotations/NamedStoredProcedureQuery.html @NamedStoredProcedureQuery ]
 
* Dynamic definition support using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/queries/StoredProcedureCall.html StoreProcedureCall]
 
* Dynamic definition support using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/queries/StoredProcedureCall.html StoreProcedureCall]
* Stored function support using StoredFunctionCall
+
* Stored function support using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/queries/StoredFunctionCall.html StoredFunctionCall]
* Object-relational data-types, Struct, Array (OBJECT types, VARRAY), including mapping using ObjectRelationalDatatypeDescriptor
+
* Object-relational data-types, Struct, Array (OBJECT types, VARRAY), including mapping using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/mapping/structures/ObjectRelationalDatatypeDescriptor.html ObjectRelationalDatatypeDescriptor]
* PLSQL types, BOOLEAN, RECORD, TABLE, using PLSQLStoredProcedureCall
+
* PLSQL types, BOOLEAN, RECORD, TABLE, using [http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/platform/oralce/PLSQLStoredProcedureCall.html PLSQLStoredProcedureCall]
  
 
A stored procedure call be used in any query to read objects, or read or modify raw data.
 
A stored procedure call be used in any query to read objects, or read or modify raw data.
Line 27: Line 27:
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class);
 
ReadAllQuery databaseQuery = new ReadAllQuery(Employee.class);
 
StoredProcedureCall call = new StoredProcedureCall();
 
StoredProcedureCall call = new StoredProcedureCall();
 +
databaseQuery.setCall(call);
  
 
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(databaseQuery);
 
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(databaseQuery);
List result = query.getResultList();
+
List<Employee> result = query.getResultList();
  
 
</source>
 
</source>
Line 35: Line 36:
 
=== Using @NamedStoredProcedureQuery to define a stored procedure ===
 
=== Using @NamedStoredProcedureQuery to define a stored procedure ===
 
<source lang="java">
 
<source lang="java">
 +
@NamedStoredProcedureQuery
 +
@Entity
 +
public class Employee {
 +
...
 +
}
 
</source>
 
</source>

Revision as of 11:05, 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.

Oracle stored procedure using OUT CURSOR

 

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();
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 {
 ...
}