On 21 mai 2012, at 21:06, Gunnar Morling wrote:
2012/5/21 Emmanuel Bernard <emmanuel(a)hibernate.org>:
>
> On 15 mai 2012, at 19:50, Gunnar Morling wrote:
>
>> I also find disabling validation of @NotNull by default problematic.
>> If I'm for instance using sequences for id generation, then @NotNull
>> should be validated upon insertion. But relying on sequences is IMO
>> per se not portable; so when deciding to use them, I'd also expect
>> @NotNull to be validated.
>
> 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.
Ah, I see. Indeed I thought that you meant to disable validation of
@NotNull in any case. If the behavior depends on the applied id
generation strategy, #3 makes more sense.
I'm not sure, does the JPA spec define that sequence values are always
to be prefetched? Otherwise I could imagine situations where an
allocation size of 1 is used, which would allow to fetch the sequence
just within the INSERT statement. In that case I think the constraints
again couldn't be validated.
The JPA provider implementation would know such thing and act accordingly.