Wednesday, April 2, 2008

JPA Toplink, and stored procedures

Blink It Digg! Dzone

If all you want to do is create extra stored procedure queries then
you might want to consider just creating a customizer and adding some
queries there. Then you won't actually need to create a project at
all.

Use the toplink.session.customizer property described at:
http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html

and then add some queries to your session. To make it even easier,
then just define your queries in JPA, and override the call in your
customizer. For example, if you defined a JPA named query called
"Employee.executeStoredProc" then in your customizer method you could
have something like:

public void customize(Session session) {
DatabaseQuery query = session.getQuery("Employee.executeStoredProc");
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("employee_stored_proc");
query.setCall(call);
}

Then when you call your JPA query the stored proc will run.