Home Services Partners Company
Options for Fine Tuning Memory Usage in Hibernate using Oracle

Options for Fine Tuning Memory Usage in Hibernate using Oracle

May 29, 2009 0 Comments


Suppose you’ve been tasked with tracking down the memory usage of your application you’ve written with Hibernate. You’ve traced and tuned, and you think you should be able to squeeze more out of your database drivers. For this specific example we’ll say that we need to tune parameter bindings.

In order to more accurately control the amount of memory the driver allocates for each parameter in the PreparedStatement using Oracle's Thin driver, you must use the OraclePreparedStatement.defineColumnType() method (which is not part of the JDBC specification). WARNING! Note that if you re-bind your parameters on a subsequent execute using larger data sizes then the driver will be silently truncate to the size specified – which is bad. Also, due to the fact that Hibernate abstracts the actual JDBC calls themselves, you lose the power to customize these calls unless you modify the Hibernate code itself (casting the PreparedStatement to an OraclePreparedStatement in the process – Yuck!). This is generally unacceptable as it’s costly to modify the Hibernate code and you have to duplicate the code changes every time you upgrade the version of Hibernate you’re using. So, there goes option 1.

Tuning memory on a per statement basis with the Connect for JDBC Oracle driver is much less costly; with our drivers you just set a connect option (initalColumnBufferSize) to set the initial size you want us to try for each parameter. Score! Now we don’t have to change Hibernate code to tune the app! Also, we don’t have the limitation of truncating the data on subsequent executes and binds; we will auto-adjust for the parameter’s size so there's no need to spend time analyzing every parameter binding.

So, option 2 seems to be the way to go – it’s easy to use and doesn’t require modifying Hibernate’s internals to get it done!

Jesse Davis

Jesse Davis

As Senior Director of Research & Development, Jesse is responsible for the daily operations, product development initiatives and forward looking research for Progress DataDirect. Jesse has spent nearly 20 years creating enterprise data products and has served as an expert on several industry standards including JDBC, J2EE, DRDA and OData. Jesse holds a bachelor of science degree in Computer Engineering from North Carolina State university.

Read next Using IBM DB2 JDBC Driver to Integrate DB2 with Amazon S3
Comments are disabled in preview mode.