-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: New constraint NotEmpty does not imply NotNull
PostPosted: Tue Nov 07, 2017 10:52 am 
Newbie

Joined: Tue Nov 07, 2017 10:35 am
Posts: 2
I just discovered a subtle bug in my application after upgrading to Hibernate Validator 6 and replacing my deprecated annotations from org.hibernate.validator.constraints with their counterparts in javax.validation.constraints.

The deprecated annotations packaged with HV were annotated with @NotNull. E.g.

Code:
@NotNull
@Size(min = 1)
@Deprecated
public @interface NotEmpty {}


Code:
@NotNull
@Repeatable(List.class)
@Deprecated
public @interface NotBlank {}


The new annotations do not include the @NotNull annotation. Is there a reason for this?

I'm currently scanning my entities for fields with @NotNull (or implied @NotNull) to mark those fields as required in my UI. This does not work anymore after the upgrade. Now I have to either scan for @NotNull, @NotEmpty, and @NotBlank or create my own composite annotations to maintain the current behavior. What is the recommended approach for this?

Thanks,

Thomas


Top
 Profile  
 
 Post subject: Re: New constraint NotEmpty does not imply NotNull
PostPosted: Fri Nov 17, 2017 10:02 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
When promoting @NotEmpty and @NotBlank from HV to the Bean Validation spec we decided to define them as composed constraints (as their previous counterparts), but instead leave this as an implementation detail to BV providers. The reason being, that the implementation can be more efficient when using a single constraint validator instead of relying on constraint composition.

So you'd indeed have to expand your scan to look for @NotNull, @NotEmpty and @NotBlank.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: New constraint NotEmpty does not imply NotNull
PostPosted: Fri Nov 17, 2017 12:41 pm 
Newbie

Joined: Tue Nov 07, 2017 10:35 am
Posts: 2
Gunnar, thanks for clarifying! I'll adjust the scanning logic accordingly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.