Hi all,
We are using Play 1.2.3 with Hibernate models.
We currently have a problem when wanting to validate a whole objects hierarchy. Some members of the root object of the
hierarchy are Lazy loaded (for performance reason). When using the "validation.valid(object.subObject)", the subObject is in fact an hibernate proxy and the validation always fails. I think this is because the validator does not accesses internally the fields but uses reflection so not provoking the load of the object from the database.
Concretely some code example:
RootObject rObject = new RootObject();
// Fill the rObject fields...
SubObject sObject = SubObject.find("whatever").first();
rObject.subObject = sObject;
...
if (rObject.subObject != null) {
validation.valid(rObject.subObject); // Will fail if subObject member is declared with "fetch = FetchType.LAZY"
...
}
To be noted that if we instanciate a new SubObject (not retrieved from DB) this works perfectly.
For the moment I solved the problem by doing an horrible getter for the subObject field like that:
public SubObject getSubObject() {
if (this.subObject != null && this.subObject instanceof HibernateProxy) {
return (SubObject) ((HibernateProxy) this.subObject).getHibernateLazyInitializer().getImplementation();
}
return this.subObject;
}
Does anybody have an idea to solve this?
Thanks.
Jérôme