In my previous post The Tale of the Happy Chef and the Picky Diner: Some thoughts on Stored Procedures and JPA, I expressed my concerns about JPA taking over database access and manipulation. In the past, I’ve used the DAO pattern for access, but I’ve often coupled it with Stored Procedures on the database side. I find SQL code embedded in java to be difficult to maintain and difficult to reuse. I favor the idea of SQL being encapsulated in Stored Procedures.

I’m new to JPA. I’m still trying to figure out what’s what. It’s clear to me that JPA, especially when used with an IDE such as Netbeans, can boost productivity. As an OOP programmer, I find the ORM model to be very appealing. But, in the end, you still have SQL embedded into Java code. Ok, so this doesn’t exactly constitute heresy, but I’m a rigid kind of person. When I get an idea in my head, I hold onto it like a squirrel and his nut. I tuck it away for the coming winter so that I can later take it out (with no small modicum of pride) for a nice mid-winter snack!

One of my acorns goes something like this:

“Why not let the RDBMS do what it does best? What better to manage your Relational Database than a Relational Database Management System?”

Maybe my Picky Diner (Java middle-tier that uses JPA)/Happy Chef (RDBMS) story was a little too one-sided. Maybe there is a way for the Picky Diner and the Happy Chef to work together. Perhaps the Picky Diner can order off the menu (stored procedures) and still use his fancy square plates (Persistence Entity Beans)? That way the Chef gets to cook and the Picky Diner still gets to eat off his plates.

My next step is to try this out. I didn’t like the idea at first, but I’m warming up to it. In plain terms, I’m hoping to do the following:

Map my Persistence Entity Bean to the OUT parameters of a stored procedure.

The little reading that I’ve done indicates that this will work, but I want to see how it feels. Will if feel natural or will it feel like I’m going against the grain? Will it require a lot of customization or will my IDE support it easily? We’ll see!