Weird problem with Spring MVC, Bean Validation using @Valid and Hibernate -


i have application uses bean validation in 50 domain classes. has worked months without problems using @valid in spring mvc controllers.

now of sudden, have made many fields "lazy" in hibernate improve performance. have had deal sorts of weird issues, equals() method no longer working, objects being in session crashing because data wasn't loaded.

i have come across weird problem am loading data session attribute on spring mvc form, view renders properly, when passed @valid, reports of fields have errors though data 100% valid.

public class educationfacility extends domainobject {      /* members */     @notempty(message = "{educationfacility.name.notempty}")     private string name;      @valid     private address address = new address();      @pattern(message = "{educationfacility.phonenumber.valid}",         regexp = "(\\()?(\\d){3}(\\))?(\\s|-)(\\d){3}(\\s|-)(\\d){4}")     private string phonenumber = "";     ... } 

here's hibernate definition:

<class name="jobprep.domain.educationfacility.educationfacility" table="education_facility">     <id name="id" column="education_facility_id" type="long">         <generator class="native" />     </id>     <property name="name" column="name"/>     <component name="address" class="jobprep.domain.educationfacility.address">         <property name="address" column="address"/>         <property name="postalcode" column="postal_code"/>         <many-to-one name="province" class="jobprep.domain.educationfacility.province" column="province_id"  />     </component>     <property name="phonenumber" column="phone_number"/>     <property name="isenabled" column="is_enabled"/>     <property name="homepageviewable" column="homepage_viewable" />     <property name="coursescreated" />     <many-to-one name="admin" class="jobprep.domain.user.admin" column="admin_id" />     <many-to-one name="director" class="jobprep.domain.educationfacility.director"                  column="director_id" cascade="all" />     <bag name="teachers" inverse="true" cascade="all-delete-orphan" order-by="username asc">         <key column="education_facility_id" />         <one-to-many class="jobprep.domain.teacher.teacher" />     </bag>     <bag name="students" inverse="true" cascade="all-delete-orphan" order-by="username asc">         <key column="student_education_facility_id" />         <one-to-many class="jobprep.domain.student.student"/>     </bag>     <bag name="iprestrictions" inverse="true" cascade="all-delete-orphan">         <key column="education_facility_id" />         <one-to-many class="jobprep.domain.educationfacility.iprestriction" />     </bag>     <bag name="allowedmodules" table="education_facility_to_module"          inverse="false" lazy="true">         <key column="education_facility_id" />         <many-to-many class="jobprep.domain.module.module" column="module_id"/>     </bag> </class> 

here's controller definition:

@controller @requestmapping("/myeducationfacility") @sessionattributes("educationfacility") @preauthorize("hasrole('role_director')") public class myeducationfacilitycontroller extends controllersupport {     .... } 

here's mvc's save method:

    @requestmapping(value = "/save", method = requestmethod.post)     public string save(@valid educationfacility educationfacility, bindingresult result, sessionstatus status) {         if(result.haserrors()) {             return view("index");         } else {             adminservice.saveeducationfacility(educationfacility);             status.setcomplete();              return redirect("?complete=true");         }     } 

here's errors spring added binding result when save() invoked spring. these totally wrong:

{org.springframework.validation.bindingresult.educationfacility=org.springframework.validation.beanpropertybindingresult: 4 errors     field error in object 'educationfacility' on field 'phonenumber': rejected value [(519) 254-3678]; codes [pattern.educationfacility.phonenumber,pattern.phonenumber,pattern.java.lang.string,pattern]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [educationfacility.phonenumber,phonenumber]; arguments []; default message [phonenumber],[ljavax.validation.constraints.pattern$flag;@29895454,(\()?(\d){3}(\))?(\s|-)(\d){3}(\s|-)(\d){4}]; default message [must of form: ###-###-####]     field error in object 'educationfacility' on field 'address.address': rejected value [windsor]; codes [notempty.educationfacility.address.address,notempty.address.address,notempty.address,notempty.java.lang.string,notempty]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [educationfacility.address.address,address.address]; arguments []; default message [address.address]]; default message [address may not empty]     field error in object 'educationfacility' on field 'name': rejected value [catholic school board]; codes [notempty.educationfacility.name,notempty.name,notempty.java.lang.string,notempty]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [educationfacility.name,name]; arguments []; default message [name]]; default message [name may not empty]     field error in object 'educationfacility' on field 'address.postalcode': rejected value [n9a 2a5]; codes [pattern.educationfacility.address.postalcode,pattern.address.postalcode,pattern.postalcode,pattern.java.lang.string,pattern]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [educationfacility.address.postalcode,address.postalcode]; arguments []; default message [address.postalcode],[ljavax.validation.constraints.pattern$flag;@29895454,[a-za-z]\d[a-za-z](\s|-)\d[a-za-z]\d]; default message [postal code must of format: a#a-#a#], educationfacility=class jobprep.domain.educationfacility.educationfacility{id=3}} 

help?

just guess, try set contraint annotations on getters instead of fields. perhaps state of fields doesn't match values returned getters due lazy-loading magic.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -