Optimizing Oracle and Hibernate performance, how it turned out

Some weeks ago I wrote down some notes for making Oracle work harder and faster with hibernate.

Those notes were collected from several places on the Internet and are supposed to help.

But they didn’t. Not for us.

Good news is that we found the problem of the bad performance and fixed it… it was all caused by foreign key integrity checks.

We got our first clue when the sysadmin detected a lot (say, 12 or so) open cursors for a simple update sentence.

We were using defaults for most of the hibernate settings and even when the update was intended to only change one column, the sql sentence set all the fields in the table for the affected row.

And Oracle fired all the checks.

I’m not sure why Oracle does not optimize this by first checking if the value has changed (if it hasn’t, then the constraints are forcedly valid), but the solution was simple… don’t update more than you need.

I have  a new friend and it is called @org.hibernate.annotations.Entity(dynamicUpdate=true). There is some (extremely brief) documentation on the hibernate annotations reference and javadocs. Of course you can also use it in the hbm files if XML is your thing.

Just in case you did not guess it, this only updates dirty properties of your objects (i.e. those that you updated after retrieving it from the database).

This has potential caveats if another transaction somehow updates your object, since the database state will be different that what you expect. To the best of my understanding this can only happen with detached objects in any reasonable isolation level… and you should reload the state from database in that case.

Well, so that was it… too many constraints on a table and updating more columns than needed. Updating only the affected columns increased performance to where we expected: better than the mysql-based prototype.

Optimizing Oracle and Hibernate performance

I’ve collected the following bits of information regarding the tunning of Oracle when used with Hibernate performance… it might help someone (and I need to write it down somewhere I won’t loose when moving from a desk to another!).

The following properties should be set:

# See http://martijndashorst.com/blog/2006/11/28/hibernate-31-something-performance-problems-contd/
# NOTE: See http://opensource.atlassian.com/projects/hibernate/browse/HHH-3359
hibernate.jdbc.wrap_result_sets = true

# See http://www.hibernate.org/120.html#A10
hibernate.dbcp.ps.maxIdle = 0
hibernate.c3p0.max_statements = 0

# Everything else comes from http://docs.codehaus.org/display/TRAILS/DatabaseConfigurations
# The Oracle JDBC driver doesn't like prepared statement caching very much.
hibernate.statement_cache.size=0
# or batching with BLOBs very much.
hibernate.jdbc.batch_size=0

I have not tested the performance difference… just collected the information.

Let me know if you know more tricks!

Update: Added a warning about a memory leak in current hibernate, thanks to dfernandez.

Update 2: Statement caching for Oracle can be enabled directly on the datasource implementation. See this article.

IAM has two new committers

This is just a brief note to publicly welcome our two new committers on Eclipse IAM:

More news soon!

Back from Eclipse Summit Europe

I am probably the last one in posting about eclipse summit, so I will make this brief and painless.

It was a great experience (my first time with the eclipse community). The event was incredibly well organized! Congratulations!

It was not perfect, though. Both IAM and M2E had new&noteworthy talks, but finally M2E was cancelled… I was hoping to meet Jason on that talk, so I was a bit disappointed.

I couldn’t meet with Ed Merks (which is one of the IAM mentors)… he is a busy guy!

Another problem… too many great talks! I was tempted for a moment to skip my IAM New & Noteworthy talk so I could attend the parallel sessions (specially Equinox P2: Provisioning your world by Jeff McAffer).

On the good side, I was able to meet with some of the Eclipse community in Spain, which seems to be focused on modeling. There are the folks from the European Software Institute, which had a poster on the first day and then some more from the MOSKitt team (who are hosting an Eclipse Day next week).

I attended the Buckminster talks (IAM added Buckminster support a while back, with some more waiting on bugzilla) and found it very interesting for several tasks, specially creating target platforms.

Finally. the two main things that I got back from ESE2008 regarding IAM are:

  • People do care about maven integration, but not only as users. Questions about integration of P2 and Maven was raised several times, so it is good to know that we have that on IAM’s project plan.
  • Users still wonder why there are 2 integration plug-ins for maven. Well, I so do I! Let’s see if we can change this in the future.

A great experience! Hope I can repeat soon!

Talk and beverages on Eclipse Summit Europe

It’s almost the time to start packing for Eclipse Summit Europe.

I’ll be arriving at Ludwigsburg this tuesday evening, so if anyone feels like having a late refreshment, let me know.

On Wednesday I’ll be assisting to some of the talks (still have not decided) and I expect to have some time to talk with other attendees.

Thursday is the day for my IAM New and Noteworthy talk. If you are interested in Maven integration in Eclipse, you should come!

Ismael Teijeiro will also be coming. He has contributed the integration of IAM with Buckminster. This a bridge between the two projects which works in both directions… IAM can use Buckminster and Buckminster can use IAM. It is an extremely interesting work, so you might want to learn more from him.

After the summit, I’ll spend a few days on Stuttgart, so you have one more chance to learn more about IAM :-) .