<p>2012/5/21 Emmanuel Bernard <<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>>:<br>
><br>
> On 21 mai 2012, at 21:06, Gunnar Morling wrote:<br>
><br>
>> 2012/5/21 Emmanuel Bernard <<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>>:<br>
>>><br>
>>> On 15 mai 2012, at 19:50, Gunnar Morling wrote:<br>
>>><br>
>>>> I also find disabling validation of @NotNull by default problematic.<br>
>>>> If I'm for instance using sequences for id generation, then @NotNull<br>
>>>> should be validated upon insertion. But relying on sequences is IMO<br>
>>>> per se not portable; so when deciding to use them, I'd also expect<br>
>>>> @NotNull to be validated.<br>
>>><br>
>>> I think you misunderstood something. If sequence, table generation or any in memory generation logic is used, then @NoNull will indeed be validated in option #3. In fact, database trigger and column id generations are the only one that would disable validation.<br>
>><br>
>> Ah, I see. Indeed I thought that you meant to disable validation of<br>
>> @NotNull in any case. If the behavior depends on the applied id<br>
>> generation strategy, #3 makes more sense.<br>
>><br>
>> I'm not sure, does the JPA spec define that sequence values are always<br>
>> to be prefetched? Otherwise I could imagine situations where an<br>
>> allocation size of 1 is used, which would allow to fetch the sequence<br>
>> just within the INSERT statement. In that case I think the constraints<br>
>> again couldn't be validated.<br>
><br>
> The JPA provider implementation would know such thing and act accordingly.</p>
<p>Right. I guess what I'm just not totally comfortable with is the fact that, when looking at an entity, it gets a bit more complicated to understand whether a @NotNull constraint is validated or not. </p>
<p>By defining a validation group such as @PreUpdate and putting the @NotNull constraint into that group a user could solve the issue in an easy-to-understand way leveraging the existing mechanisms.</p>
<p>I see that such a feature would probably help to give a better "it-just-works" experience. But one could also argue that using a sequence (or another id generation strategy not providing a value before the insert) and a @NotNull constraint within a group which is validated upon insertion represents an inconsistency within the data model.</p>
<p>On a more practical side: How would a JPA provider implement that feature? The simplest would probably be to validate all constraints and then ignore any id-related violations based on the chosen generation strategy. Or do you think we should define a way to control whether certain constraints are to be excluded by the BV runtime?</p>
<p>--Gunnar<br>
> _______________________________________________<br>
> beanvalidation-dev mailing list<br>
> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a></p>