Hi, Pedro. In this case you should be using a <getter> instead of a <field> in your XML-based constraint declarations (and, as it turns out, that makes this a question for the user list ;) ). It also looks like you're not using the latest BVal release; we encourage you to give Apache BVal 0.4 a try!
Regards, Matt On Thu, May 17, 2012 at 12:04 PM, Pedro Quiñonez <[email protected]> wrote: > hi team members, > > Over last date I tried to use the Apache Bean Validation with two beans, A > extends the attributes and methods from B. The constraint configuration in > the contraint.xml file, use constraints over the A class fields and methods > that extend from B class. > > At the moment to execute the example i get the next exception: > > *Caused by: javax.validation.ValidationException: > gsa.dsc.jsr303.bean.module.MM_SA_DataBean does not contain the fieldType > acct_stat_cd* > at > org.apache.bval.jsr303.xml.ValidationMappingParser.processFieldLevel(ValidationMappingParser.java:360) > at > org.apache.bval.jsr303.xml.ValidationMappingParser.processMappingConfig(ValidationMappingParser.java:96) > at > org.apache.bval.jsr303.ApacheValidatorFactory.configure(ApacheValidatorFactory.java:121) > at > org.apache.bval.jsr303.ApacheValidatorFactory.<init>(ApacheValidatorFactory.java:105) > > The question is, the bean validation support validations over fields and > methods that are extends from one class base? > > public class *BaseDB2DataBean *{ > > /** Variable estatus cuenta */ > protected String acct_stat_cd = null; > > } > > > *MM_SA_DataBean* extends *BaseDB2DataBean*{ > > } > > *sa-constraints.xml* > <bean class="gsa.dsc.jsr303.bean.module.MM_SA_DataBean"> > > <field name="acct_stat_cd"> > > <constraint annotation="javax.validation.constraints.NotNull" /> > > <constraint > annotation="javax.validation.constraints.Pattern"> > <element name="regexp"> > <value>AC</value> > </element> > </constraint> > </field> > </bean> > > > > public static void main(String[] args) { > Validator validator = > Jsr303ValidatorFactory.SINGLE_INSTANCE.getValidator(); > > MM_SA_DataBean bean = new MM_SA_DataBean(); > > bean.setAcct_stat_cd("DE"); > bean.setPlattform("MOVISTAR"); > bean.setTechnology("4G"); > > Set<ConstraintViolation<MM_SA_DataBean>> result = null; > Iterator<ConstraintViolation<MM_SA_DataBean>> it = null; > > long init = System.currentTimeMillis(); > result = validator.validate(bean); > long end = System.currentTimeMillis(); > > System.out.println("Tiempo ejecución: [" + (end - init)+ "]"); > > it = result.iterator(); > > while(it.hasNext()){ > ConstraintViolation<MM_SA_DataBean> bean1 = it.next(); > System.out.println("Valor:" + bean1.getInvalidValue() + " > Mensaje:" + bean1.getMessage()); > } > }
