Difference between revisions of "CRV2 RevCodePersistentAntiPatternJava"

From OWASP
Jump to: navigation, search
Line 1: Line 1:
 
=Java Persistence anti-patterns=
 
=Java Persistence anti-patterns=
  
==Spring –Hibernate Lazy loading==
+
==Spring –Hibernate Anti-patterns==
  
 +
===Lazy loading===
 
This feature reduces the handling of data in an asynchronous way, which avoids unnecessary requests to the database, however it can causes problems with persistence.  
 
This feature reduces the handling of data in an asynchronous way, which avoids unnecessary requests to the database, however it can causes problems with persistence.  
 
Errors associated with Lazy loading are:
 
Errors associated with Lazy loading are:
Line 9: Line 10:
 
  unsaved-value mapping was incorrect)
 
  unsaved-value mapping was incorrect)
  
===N+1 Select issue===
+
====N+1 Select issue====
 
This problem occurs when the collection is returned from the database, containing n+1 separate queries instead of a single join query. This issue is quite challenging to solve because it depends on the specific implementation of the code, therefore look for the following executions:
 
This problem occurs when the collection is returned from the database, containing n+1 separate queries instead of a single join query. This issue is quite challenging to solve because it depends on the specific implementation of the code, therefore look for the following executions:
 
*Control that mapping configurations are updated for affected domain classes
 
*Control that mapping configurations are updated for affected domain classes
 
*Add the @ManyToMany @Fetch(FetchMode.JOIN) as a query strategy  to override the Lazy behavior if necessary
 
*Add the @ManyToMany @Fetch(FetchMode.JOIN) as a query strategy  to override the Lazy behavior if necessary
 
*Review Tuning fetching strategies from Hibernate reference (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-fetching-custom)
 
*Review Tuning fetching strategies from Hibernate reference (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-fetching-custom)
 +
 +
====Hibertane issues with DAO (Data Access Objects): Sessions per Operation anti-pattern====
 +
 +
Control proper implementation of persistence context. Problem occurs when DAO use different persistence context for each one, in other words, a different Session or EntityManager.

Revision as of 18:44, 21 September 2013

Contents

Java Persistence anti-patterns

Spring –Hibernate Anti-patterns

Lazy loading

This feature reduces the handling of data in an asynchronous way, which avoids unnecessary requests to the database, however it can causes problems with persistence. Errors associated with Lazy loading are:

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or    
unsaved-value mapping was incorrect)

N+1 Select issue

This problem occurs when the collection is returned from the database, containing n+1 separate queries instead of a single join query. This issue is quite challenging to solve because it depends on the specific implementation of the code, therefore look for the following executions:

Hibertane issues with DAO (Data Access Objects): Sessions per Operation anti-pattern

Control proper implementation of persistence context. Problem occurs when DAO use different persistence context for each one, in other words, a different Session or EntityManager.