Difference between revisions of "EclipseLink/Examples/JPA/IntegrityChecker"

From Eclipsepedia

Jump to: navigation, search
(How to validate the mappings against the database)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
[[Category:EclipseLink/Example/JPA|IntegrityChecker]]
 +
 
= How to validate the mappings against the database =
 
= How to validate the mappings against the database =
  
Line 18: Line 20:
 
}
 
}
 
}
 
}
<source>
+
</source>
  
 
== Configuring the SessionCustomizer ==
 
== Configuring the SessionCustomizer ==
  
A session customizer can be configured in the persistence unit's properties in either XML or in a properties Map passed to <tt>Persistence.createEntitymanagerFactory("unit-name", properties)</tt>.
+
A session customizer can be configured in the persistence unit's properties in either XML or in a properties Map passed to <tt>Persistence.createEntityManagerFactory("unit-name", properties)</tt>.
  
<source lang-java>
+
<source lang=java>
 
properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, EnableIntegrityChecker.class.getName());
 
properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, EnableIntegrityChecker.class.getName());
<source>
+
</source>

Latest revision as of 12:54, 25 November 2009


[edit] How to validate the mappings against the database

By default EclipseLink assumes that the provided metadata matches the underlying database. This assumption is made to speed up application bootstrapping. During development however it is possible to enable validation of the mappings against the database using the IntegrityChecker. This how-to focuses on using the IntegrityChecker with EclipseLink JPA.

Contents


[edit] Enabling the IntegrityChecker

This must be done using a session customizer:

public static class EnableIntegrityChecker implements SessionCustomizer {
 
	public void customize(Session session) throws Exception {
		session.getIntegrityChecker().checkDatabase();	
		session.getIntegrityChecker().setShouldCatchExceptions(false);
	}
}

[edit] Configuring the SessionCustomizer

A session customizer can be configured in the persistence unit's properties in either XML or in a properties Map passed to Persistence.createEntityManagerFactory("unit-name", properties).

properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, EnableIntegrityChecker.class.getName());