Saturday, December 12, 2009

JPA - Hibernate Performance Tips

Couple of performance tunning in Hibernate which came out very handy,

1. @org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true) adding this to the entity ensures, only the columns for which values are supplied will be inserted and the value modified will be updated. This is very effective if updates are set for archival logging.

2. Cascade is an important parameter when it comes to relationship, as it decides when a parent object is persisted what are the associated object to be checked and updated. If you are not updating the associated relationships you can avoid the child object being checked for modification which results in lot of performance benefit.

Define the Cascade explicitly based on what type of association need to be built.

OneToMany ( cascade = {Cascade.ALL} ).

PERSIST,MERGE,REMOVE,REFRESH,DELETE,SAVE_UPDATE,REPLICATE,DELETE_ORPHAN,LOCK,EVICT

Reference,
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-hibspec-cascade

No comments: