Forums Register Login

Caching EJB stored procedure calls.

+Pie Number of slices to send: Send
We have an application that is using a stateless session bean to call a stored procedure using straight JDBC.

Sesson bean calls a class which has

connection = getDataSource().getConnection();
Proc = connection.prepareCall(spString);
rs = proc.executeQuery();

The problem is that the none of the data retrieved by the SP is cached at the JVM level. All calls result in a round trip to the database even if the same search is executed twice in a row and brings back the same data each time. This kills performance. I have read some of the posts describing how stored procedures can be called from EJBs i.e stateful beans but it is not clear if the EJB will cache the results of a stored procedure if the search parameters are the same.

Any suggestions on the best strategy to follow?

The ejb spec is 2.2
The App Server is WebSphere.
+Pie Number of slices to send: Send
Hi Patrick,

why do you expect any caching when using stored procedures? Usually stored procedures just give you the possibility to save some complex queries (maybe consisting of more than one client command) on the server side. This often speeds up executing the stored procedure again but it doesn't avoid a real round-trip to the database server. And I think that there's no big difference with session beans executing a stored procedure.

I guess to solve the performance problems you'll have to use some additional caching framework or create your own caching mechanism (if it's even possible or reasonable to do caching!).

Marco
+Pie Number of slices to send: Send
Patrick,

It sounds like you are confused about the WebSphere prepared statement cache. That just caches the "compiled" statement itself, not the results of executing the statement. If you can't move to JPA right now, look into caches like EHCache or Coherence.

Regards,
Reza
+Pie Number of slices to send: Send
I am not referring to the WAS prepared statement cache.

Data returned by EJBs is cached in the JVM memory. Works like the Hibernate Level 1/Level 2 cache. So the data returned by a stored procedure called by an EJB would be cached in memory. That's the performance gain.
+Pie Number of slices to send: Send
Persistence Manager may do the trick.

http://www-01.ibm.com/support/docview.wss?uid=swg21189749
+Pie Number of slices to send: Send
If you want to cache individual rows, that's what Entity EJBs are for. In essence, an entity bean is a JavaBean that's effectively managed as though it was a member of a hash whose keys are the primary keys of the EJBs.

Entity EJBs can back the results of a stored procedure execution, although just for the record, I don't recommend stored procedures unless there is a compelling reason to use them. I've experienced some of their liabilities firsthand recently.
+Pie Number of slices to send: Send
Got a reply from IBM and there are no extensions in WAS that explicitly Stored Procedures so we are going to experiment with CMP EJBs. We may check out Hibernate as well.
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2277 times.
Similar Threads
SP not being called successfully in a J2EE app
How to call database stored procedures using EJB ??
Transaction Control for a method.
Callling Stored Procedures from CMP
Transaction Management when stored procedure calls Java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:44:42.