Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/JPA 2.0/validation api integration"

(JPA 2.0: Validation API Integration)
(JPA 2.0: Validation API Integration)
Line 4: Line 4:
 
[[EclipseLink/Development/JPA_2.0 | JPA 2.0 Root]] |  {{bug|266927}}
 
[[EclipseLink/Development/JPA_2.0 | JPA 2.0 Root]] |  {{bug|266927}}
  
{|{{BMTableStyle}}
+
==Issue Summary==
|-{{BMTHStyle}}
+
JPA 2.0 spec mandates that a persistence provider needs to validate managed classes (entities, mapped superclasses, and embeddable classes) using Bean Validation API(JSR-303) on lifecycle events. Please see JPA spec section 3.6 for more details.
! Date
+
! Committer(s)
+
! Description
+
|-
+
| March 3, 2009 || [[User:Gordon.yorke.oracle.com | gyorke]] || Initial feature template
+
|-
+
|-
+
  
|-
+
==General Solution==
|}
+
=== Goals ===
 +
* EclipseLink should not require either Bean Validation API or a Bean Validation Provider at run time if Bean Validation is not enabled.
 +
* There should be no performance overhead at runtime if Bean Validation is disabled
 +
* There should be no dependency from foundation to jpa module
  
== Summary==
+
===Bootstrapping of ValidatorFactory and other Validation metadata===
 +
'''Validation Mode:'''  Specified by user as value of property "javax.persistence.validation.mode" or as "validation-mode" element in persistence.xml.<br>
 +
'''Validation Groups:''' Specified by user as value of property "javax.persistence.validation.group.pre-*". It is specified as comma separated fully qualified class names of the groups.<br>
 +
'''ValidatorFactory:''' An instance of the factory would be used to obtain Validator used to perform validation. ValidatorFactory is obtained in one of following ways as specified by JPA spec:
 +
* Passed as value of property "javax.persistence.validation.factory" while creating EMF using Persistence.createEMF() or from a JavaEE container
 +
* While running in JavaSE mode, created by EclipseLink using Validation.buildDefaultValidatorFactory()
  
In JPA 2.0 the specification has defined requirements to integrate with the Validation API (JSR-303).
+
===Wiring EclipseLink to trigger Bean Validation on lifecycle events===
The details are to be determined.
+
* Introduce a DescriptorEventListener listener called BeanValidationListener.
 +
** BeanValidationListener would be initialized with ValidatorFactory, Validation Mode, Validation Group and a pointer to the MetaDataProject
 +
* Install this listener at deployment time if Bean Validation is enabled
 +
* BeanValidationListener performs Bean Validation on life cycle events prePersit, preUpdate and preRemove
  
Multiple sections
+
===Disabling cascading of validation===
 +
Spec requires that while executing automatic validation, Validation cascade (@Valid) must not occur for entity associations (single- or multi-valued).
 +
* When obtaining a Validator instance to perform validation, supply a TraversableResolver that can identify entity associations.
  
=== Work Estimate ===
+
Need to expand on this further
  
* Integation work
 
*: approx 5 days
 
* Develop Testing
 
*: approx 3 days
 
* Document and execute Validation implementation plan.
 
*: approx 5 days
 
  
== Concepts ==
+
=== Open Issues ===
  
== Functional Requirements ==
 
  
* Support integration with Validation API (jsr-303) as defined by JPA specification
 
 
== Design ==
 
 
=== Design Constraints ===
 
 
== API ==
 
 
== Documentation ==
 
 
== Implementation ==
 
== Testing ==
 
 
== Open Issues ==
 
 
This section lists the open issues that are still pending that must be decided prior to fully implementing this project's requirements.
 
 
{|{{BMTableStyle}}
 
|-{{BMTHStyle}}
 
! Issue #
 
! Owner
 
! Description / Notes
 
|-
 
|
 
|
 
|
 
|}
 
 
== Decisions ==
 
 
This section lists decisions made. These are intended to document the resolution of open issues or constraints added to the project that are important.
 
 
{|{{BMTableStyle}}
 
|-{{BMTHStyle}}
 
! Issue #
 
! Description / Notes
 
! Decision
 
|-
 
|
 
|
 
|
 
|}
 
  
 
== Future Considerations ==
 
== Future Considerations ==
 
+
* Bean Validation Meta Data constraints like @Size can be used at DDL generation time.
During the research for this project the following items were identified as out of scope but are captured here as potential future enhancements. If agreed upon during the review process these should be logged in the bug system.
+
 
+
== References ==
+

Revision as of 21:11, 14 July 2009

JPA 2.0: Validation API Integration

JPA 2.0 Root | bug 266927

Issue Summary

JPA 2.0 spec mandates that a persistence provider needs to validate managed classes (entities, mapped superclasses, and embeddable classes) using Bean Validation API(JSR-303) on lifecycle events. Please see JPA spec section 3.6 for more details.

General Solution

Goals

  • EclipseLink should not require either Bean Validation API or a Bean Validation Provider at run time if Bean Validation is not enabled.
  • There should be no performance overhead at runtime if Bean Validation is disabled
  • There should be no dependency from foundation to jpa module

Bootstrapping of ValidatorFactory and other Validation metadata

Validation Mode: Specified by user as value of property "javax.persistence.validation.mode" or as "validation-mode" element in persistence.xml.
Validation Groups: Specified by user as value of property "javax.persistence.validation.group.pre-*". It is specified as comma separated fully qualified class names of the groups.
ValidatorFactory: An instance of the factory would be used to obtain Validator used to perform validation. ValidatorFactory is obtained in one of following ways as specified by JPA spec:

  • Passed as value of property "javax.persistence.validation.factory" while creating EMF using Persistence.createEMF() or from a JavaEE container
  • While running in JavaSE mode, created by EclipseLink using Validation.buildDefaultValidatorFactory()

Wiring EclipseLink to trigger Bean Validation on lifecycle events

  • Introduce a DescriptorEventListener listener called BeanValidationListener.
    • BeanValidationListener would be initialized with ValidatorFactory, Validation Mode, Validation Group and a pointer to the MetaDataProject
  • Install this listener at deployment time if Bean Validation is enabled
  • BeanValidationListener performs Bean Validation on life cycle events prePersit, preUpdate and preRemove

Disabling cascading of validation

Spec requires that while executing automatic validation, Validation cascade (@Valid) must not occur for entity associations (single- or multi-valued).

  • When obtaining a Validator instance to perform validation, supply a TraversableResolver that can identify entity associations.

Need to expand on this further


Open Issues

Future Considerations

  • Bean Validation Meta Data constraints like @Size can be used at DDL generation time.