Can the Picky Diner learn to get along with the Happy Chef?


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!

Advertisements

2 thoughts on “Can the Picky Diner learn to get along with the Happy Chef?

  1. I’m interested in knowing what was the outcome of mapping SP OUT parameters to the entity bean?

    We’re struggling with the same issues, leaning towards the persistence layer but we have some really mean SPs that historically produced massive performance improvements over out-of-SP code. It looks like a mixture but controlled heavily in favour of JPA.

  2. Lawrence, I believe both Hibernate and Toplink have methods for doing this. Check out Hibernates Native Query

    http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-querying-nativesql

    And Toplink’s StoredProcedureCall
    http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qrybas004.htm#BCFIJIIH

    As for the direction I ended up determining for my team, you can read about it here:

    https://davidwburns.wordpress.com/2008/03/10/why-i-chose-or-mapping-jpa-over-stored-procedures-for-crud/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s