[hibernate-issues] [Hibernate-JIRA] Commented: (HV-76) Field annotated member validators does not work with proxied objects

Markus Lang (JIRA) noreply at atlassian.com
Wed Feb 11 10:55:41 EST 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HV-76?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32362#action_32362 ] 

Markus Lang commented on HV-76:
-------------------------------

I also have some trouble within my Hibernate environment when it comes to validating (initialized) proxy instances. Beside the patch provided by Lucien I also have trouble with values returned by getter calls that are uninitialized proxy instances. Therefore I've wrapped the _Validator.isValid()_ calls with an additional _Hibernate.isInitialized(value)_ check.

The part of Lucien's patch regarding unproxying the bean instance will fail if the to be validated bean instance doesn't have an attached session instance any more. Therefore I've used the _LazyInitializer.getImplementation()_ method for querying the wrapped bean instance of the proxy. I'm not sure if it's a good idea to always use the _LazyInitializer_ class for getting the original bean instance but for me it's working fine with detached persistent entities.

I hope my provided patch (initialized-proxy-fix.patch) against the current 3.1.0.CR2 SVN branch is able to improve the validation results for beans wrapped by a Hibernate proxy instance.

>  Field annotated member validators does not work with proxied objects
> ---------------------------------------------------------------------
>
>                 Key: HV-76
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-76
>             Project: Hibernate Validator
>          Issue Type: Bug
>    Affects Versions: 3.0.0.ga, 3.1.0.CR1
>            Reporter: Lucien Weller
>         Attachments: initialized-proxy-fix.patch, proxy-fix.patch, testcase.tar.gz
>
>
> Copied from subtask HV-68 as subtask of closed issue HV-64 seams not to appear as open issue):
> May be annotating validation constraints on field level ist not the best solution, but by now it's explicitly mentioned as a possibility without other indication of restrictions in hibernate validator doc. But obviously this method is not safe with hibernate proxy instances as it is demonstrated be test case attached to original issue (http://opensource.atlassian.com/projects/hibernate/secure/attachment/14092/testcase.tar.gz). My first patch was a quick fix that worked for our case and a agree once again that it may have some side effects as it changes the semantic of field annotation. but my second solution (http://opensource.atlassian.com/projects/hibernate/secure/attachment/14091/proxy-fix.patch) leaves every thing as it is and just handles proxy instances differently and produce a more correct validation result than in current version.
> I hope that you can do something with my ideas or a least document this limitation when using field annotation. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list