Field annotated member validators does not work with proxied objects

Description

Every thing works fine, except when I try to validate an persistent instance laded directly from database (which should obviously be valid) we get some invalid values reported by hibernate class validator.

After debuging hibernate validator code, I discovered that it is because we annotate our hibernate classes on field level with validator anotaions (getter and setter are generated in our project). Hibernate validator then tries to retrive the value directly by accessing the field it self. But if the instance is a proxied object (due to lazy loading), fields don't hold the correct value (in fact they all set to null) and validator then reports an invalid value if field is annotated with not null validator.

I simply fixed this isse by accessing fields with their getter rather than by a direct access if a getter has been defined. Now validation also works fine with persistent proxied instances loaded from database.

The corresponding patch is attached to the present issue report, hoping this will be fixed in 3.1.0.GA release

Environment

None

Activity

Show:
Emmanuel Bernard
August 12, 2008, 12:28 AM

I cannot apply your patch as it breaks a lot of semantics on what to expect.

Lucien Weller
August 18, 2008, 5:29 PM

Ok, my first patch was a quick fix that works in our case because our beans are pojo's with simple getter/setters. So I tried to go a little bit further and found a solution where proxies could be handled correctly withoud changin the current semantic. The diadvanage is that this fix has a dependency to hibernate-core (but as a saw in pom of hobernate validator, this dependency is already requiredm so I think it does not matter).

I hope that this new patch will help you and lead to a reopening of this issue (I couldn't repoen it my myself because I don't have enough right's).

Lucien Weller
August 18, 2008, 5:29 PM

new patch that handles proxies correctly

Lucien Weller
August 18, 2008, 5:32 PM

here is my simple test case that allows to reproduce the bug

Assignee

Unassigned

Reporter

Lucien Weller

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

Priority

Major
Configure