Hobione's Weblog

Living & Breathing in Web 2.0 Era

Store Procedures + JPA – Performance Issue

If we call store procedures from JPA, are we going to loose any performances? Our concern is, may be we should think either JPA or store procedures. If we decide to use both, we might not take full advantages either or, please correct me if I am wrong.

Seems like you’re worried about performance without having anything to measure. That’s something to avoid.

Bottom line, I have seen companies:

– Use strictly stored procedures
– Use no stored procedures
– Use a mix

I have seen successes and failures in both cases.

Performance issues are related more to your schema, locking strategy and access mechanisms than to using stored procedures versus an ORM.

Using JPA will probably get you something to demonstrate faster and sooner. It also allows you to work with different database vendors – which may not be an issue. As you develop, make sure you’re hitting the high-value stuff from the customer or user’s perspective early. When/if you find performance issues, fix them. That’s the best thing you can do.

Don’t start de-normalizing your schema until you absolutely must. Start with as close to 3rd normal form as you can manage (higher-order normalization is not often worth it). Use views before you de-normalize. Views will slow down inserts but increase reads, which is probably what you’re more concerned about. IF your system does more writing than reading in some places, don’t use views there.

Until you know what your users are going to be doing, you cannot optimize your stuff. So you MUST keep it clean and un-optimized so that when you’re ready to start making performance enhancements based on ACTUAL DATA, you’re starting with less of a mess. It is VERY hard to optimize code in one direction if it has been optimized in another.

Finally, you’re a service. Independent of technology, a remote service needs to have chunky (opposite of fine-grained) API calls. Your individual methods (regardless of state) should do a lot in each request. WHY? The overhead of a remote class versus a local call is 10,000X or much worse.

Web services are no exception. You’re going to need to have chunky messages. The communication protocol is going to be SOAP of HTTP, right? HTTP is not fast and SOAP is bloated, so your messages are going to require multiple IP packets. Your messages will need to do a lot.

Oracle Toplinks vs. Hibernate, is there any advantage one over other or this is just a personal choice?

I have no idea. Toplink has been around many more years. I believe Hibernate is a better design. I don’t know that you’ll notice much of a difference.

HOWEVER, if you use JPA, it won’t matter as much. JPA gives you one level of indirection on top of your ORM.

In your wiki site, you have tutorials for pure JPA and EJB 3 and JPA, would you explain differences between two.

JPA can be used in a JSE environment. When you do so, it’s like using JDBC on steroids (I would no longer recommend using JDBC if you can use JPA).

However, JPA by itself does not start/stop transactions. You must manage sessions, etc. That’s not a bad thing, it’s just a thing.

When you use EJB3, you get JPA automatically. There is a key difference (ignoring extended contexts)

– Every individual method on a session bean starts a transaction
– When you leave that method, the transaction is committed unless rollback was enabled during the processing
– You get a new session (first level cache) at the beginning of each method
– That session is dumped when you leave the method.

So every call to a session beans commits changes and creates and then destroys a session.

You also have an extended context. The extended context maintains cached objects (the session/1st level cache) between method invocations. It does so until a method annotated with (I believe) @Remove is called.

 

Advertisements

March 5, 2008 - Posted by | Java Persistence API

No comments yet.

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

%d bloggers like this: