Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/JPA/IntegrityChecker"
< EclipseLink | Examples | JPA
(New page: = 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 applic...) |
(→How to validate the mappings against the database) |
||
Line 1: | Line 1: | ||
= How to validate the mappings against the database = | = 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 | + | 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 [http://wiki.eclipse.org/Configuring_a_Session_(ELUG) IntegrityChecker]. This how-to focuses on using the IntegrityChecker with EclipseLink JPA. |
__TOC__ | __TOC__ | ||
+ | |||
+ | |||
+ | == Enabling the IntegrityChecker == | ||
+ | |||
+ | This must be done using a session customizer: | ||
+ | |||
+ | <source lang=java> | ||
+ | public static class EnableIntegrityChecker implements SessionCustomizer { | ||
+ | |||
+ | public void customize(Session session) throws Exception { | ||
+ | session.getIntegrityChecker().checkDatabase(); | ||
+ | session.getIntegrityChecker().setShouldCatchExceptions(false); | ||
+ | } | ||
+ | } | ||
+ | <source> | ||
+ | |||
+ | == 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>. | ||
+ | |||
+ | <source lang-java> | ||
+ | properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, EnableIntegrityChecker.class.getName()); | ||
+ | <source> |
Revision as of 10:06, 3 April 2008
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.
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); } } <source> == 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>. <source lang-java> properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, EnableIntegrityChecker.class.getName()); <source>