[hibernate-dev] [Bean Validation] XML Mapping schema
Emmanuel Bernard
emmanuel at hibernate.org
Mon Jan 19 19:35:43 EST 2009
Here is my very first attempt to describe the constraint mapping XML
schema.
I did not look at other product approach to avoid being tainted. If
you have examples of alternative approach, I would appreciate a link.
A couple of comments:
- I would have preferred a Web Beans style XML approach but this kind
of approach is getting some heavy resistance from some members of the
expert committee. So I fell back to a more classic approach.
- constraints themselves cannot be defined: you have to write an
actual annotation. I wonder if we should provide such model. At
minimal we might want to provide a way to override the constraint
validator for a given constraint.
- I used JPA 2 mapping schema as inspiration
- I stayed very close to the Java structure
Better names, enhancements, alternative proposals are welcome.
Emmanuel
<?xml version="1.0" encoding="UTF-8"?>
<validation-mappings>
<package>com.acme.dvdstore.model</package>
<bean class="Customer">
<class>
<constraint annotation="com.acme.validate.SafeCustomer">
<attribute name="category">
<array-
element>com.acme.validate.SecurityLevel.SECURED_COUNTRY</array-element>
<array-
element>com.acme.validate.SecurityLevel.SECURED_ADDRESS</array-element>
<array-
element>com.acme.validate.SecurityLevel.SECURED_FINANCIALS</array-
element>
</attribute>
<attribute name="failPerCategory">false</attribute>
</constraint>
</class>
<fields>
<field name="firstname">
<ignore-annotations/>
<stop-inheritance/>
<constraint annotation="javax.validation.Min">
<message>{error.tooSmall}</message>
<groups>
<group>javax.validation.groups.Default</group>
</groups>
<attribute name="value">45</attribute>
</constraint>
</field>
</fields>
<getters>
<getter name="firstname">
<ignore-annotations/>
<stop-inheritance/>
<constraint annotation="javax.validation.Min">
<message>{error.tooSmall}</message>
<groups>
<group>javax.validation.groups.Default</group>
</groups>
<attribute name="value">45</attribute>
</constraint>
</getter>
</getters>
</bean>
</validation-mappings>
More information about the hibernate-dev
mailing list