Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Examples/JPA/IntegrityChecker
< EclipseLink | Examples | JPA
Revision as of 10:08, 3 April 2008 by Douglas.clarke.oracle.com (Talk | contribs) (→Configuring the SessionCustomizer)
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
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); } }
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());