[hibernate-issues] [JIRA] (BVAL-237) Expose validated bean via ConstraintValidatorContext

l0coful (JIRA) jira at hibernate.atlassian.net
Thu May 14 07:37:26 EDT 2020


l0coful ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5c8fa77befd65d2d3d464aa0 ) *commented* on BVAL-237 ( https://hibernate.atlassian.net/browse/BVAL-237?atlOrigin=eyJpIjoiYWM2ZmYwNzZjOWQ1NGQ2N2JlOWYwMmQwNjYzOGE4ODEiLCJwIjoiaiJ9 )

Re: Expose validated bean via ConstraintValidatorContext ( https://hibernate.atlassian.net/browse/BVAL-237?atlOrigin=eyJpIjoiYWM2ZmYwNzZjOWQ1NGQ2N2JlOWYwMmQwNjYzOGE4ODEiLCJwIjoiaiJ9 )

That’s really unfortunate that for 7 years such a simple fix hasn’t been added to hibernate validator, and that’s because “in some situations this bean would be null”. So what?

Note that without this feature you cannot do any contextual validation with hibernate validator, like for example this:

@Entity class User {

 protected Country country;
 
 @GovId
 protected String govId;

}

If you want to use this entity to represent users from different countries, and you want to implement @GovId validator so that it uses different validation for users from different countries, you currently cannot do it with hibernate validator because there’s no way to access country field of the User entity from the validation context.

Fortunately there’s a way to do it using beans validation implementation from Micronaut framework which apparently doesn’t have a problem with injecting root bean into the validation context.

( https://hibernate.atlassian.net/browse/BVAL-237#add-comment?atlOrigin=eyJpIjoiYWM2ZmYwNzZjOWQ1NGQ2N2JlOWYwMmQwNjYzOGE4ODEiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/BVAL-237#add-comment?atlOrigin=eyJpIjoiYWM2ZmYwNzZjOWQ1NGQ2N2JlOWYwMmQwNjYzOGE4ODEiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100126- sha1:a719cbc )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200514/1d8d5580/attachment.html 


More information about the hibernate-issues mailing list