DB2 Hibernate Performance Improvements

While doing DB2 performance reviews for clients over the years, I’ve discovered that many times their projects are using Hibernate as their DB2 Object Relational Mapping (ORM) interface.  While DB2 and Hibernate can produce tremendous performance there are many best practices to achieve that goal.  The following DB2 Hibernate performance improvement techniques will help your project get the best performance out of your DB2 Java application.

First, know your SQL and do a DB2 EXPLAIN of your Hibernate SQL classes. When defining your DB2 Hibernate performance SQL make sure to include a developer or DBA who can do a DB2 SQL EXPLAIN on your team.  A DB2 SQL EXPLAIN of your Hibernate SQL queries will verify that your SQL is as efficient as possible.  The DB2 EXPLAIN process can document that the SQL is using your database indexes and joining tables on common indexed keys.

Also, the ORM Hibernate is not exempt from SQL injection so during the review of the Hibernate SQL definitions, the SQL should be checked for use of parameter makers “?” within the SQL statements and WHERE clause definitions.  Making sure to use parameter makers instead of raw Java data types removes the risk of SQL injection.  Using parameter markers helps Hibernate and DB2 cache the SQL and possibly reuse the previously optimized SQL within the DB2 system for faster execution and better DB2 Hibernate performance.

Second, understand your Hibernate usage.  Transaction path length is the most important item within any Java application and Hibernate can be good at caching your database objects to eliminate trips to the database.  Unfortunately, DB2 Hibernate performance configurations can sometimes camouflage poor SQL result set handling.  As I wrote in last week’s blog, it’s very important for the SQL to only return the database rows absolutely necessary and sometimes the DB2 Hibernate activity is Java coded with a format using several loops.  The DB2 Hibernate performance will suffer from the bad looping Java code, potentially performing too many trips to the database and/or pushing too much data across the network.  Instead of a simple efficient single SQL statement being executed, a series of DB2 Hibernate loops are executed through the objects causing poor Hibernate performance and DB2 locking issues.

Finally, understand the DB2 Hibernate performance interface activities.  Using DB2 Hibernate performance can speed up your application developers’ productivity and help them reference database information in their Java code.  Unfortunately, Java programmers don’t always know when they are triggering Hibernate database SQL activities.  Since Hibernate naming standards are sometimes lacking, make sure the transaction design is reviewed to avoid unnecessary looping, and proper Hibernate SQL activity sequence.

Since Hibernate uses Java Session synchronization to maintain its persistent state with the database, make sure that transactions follow a sequence of reading the database first and then doing the updates, inserts or deletes.  Check and improve the Hibernate FLUSHMODE settings that may have defaulted to flush the cache after every commit or after every database SQL change statement.  By performing the read SQL activities first, cache flushing can be minimized, helping the Java JVM memory management and providing the best DB2 Hibernate performance available.

These are only three areas of opportunity to improve DB2 Hibernate performance.  Make sure to understand your SQL EXPLAIN Access types, when your java Hibernate objects are really database objects, and then you can make sure they are referenced in the optimized cache order to start your project on its way for getting the best DB2 Hibernate performance possible.

_______________________________________________________

Dave Beulke is an internationally recognized DB2 consultant, DB2 trainer and education instructor.  Dave helps his clients improve their strategic direction, dramatically improve DB2 performance and reduce their CPU demand saving millions in their systems, databases and application areas within their mainframe, UNIX and Windows environments.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>