Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/CRUDStoredProcedures

< EclipseLink‎ | Examples‎ | JPA
Revision as of 13:57, 9 May 2011 by Unnamed Poltroon (Talk) (New page: CRUDStoredProcedures __TOC__ It is possible to override any EclipseLink generated SQL with custom SQL or a stored procedure call. For the CRUD (Create...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

It is possible to override any EclipseLink generated SQL with custom SQL or a stored procedure call. For the CRUD (Create, Read, Update, Delete) operations these are by default generated by EclipseLink. Each of these operations can be overridden through using a DescriptorCustomizer and the DescriptorQueryManager API.

Custom SQL or stored procedures can be used to perform different functionality, or to adhere to specific security requirements or corporate policies. Note that usage of a stored procedure to execute the same SQL as would be generated will not improve performance.

Oracle insert stored procedure

CREATE PROCEDURE EMP_INSERT (
	RESULT_CURSOR OUT CURSOR_TYPE.ANY_CURSOR) AS
BEGIN 
OPEN RESULT_CURSOR FOR SELECT e.*, s.* FROM EMPLOYEE e, SALARY s WHERE e.EMP_ID = s.EMP_ID; 
END;

Using DescriptorCustomizer to use a stored procedure for insert

import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.queries.StoredProcedureCall;
 
public class MyCustomizer implements DescriptorCustomizer {
  public void customize(ClassDescriptor descriptor) {
    StoredProcedureCall call = new StoredProcedureCall();
    call.setName("EMP_INSERT");
    call.addArgument();
    descriptor.getQueryManager().setInsertCall(call);
  }
}

Back to the top