[hibernate-dev] ORM DDL doesn't reflect BV constraints with validation mode CALLBACK

Gunnar Morling gunnar at hibernate.org
Sat Feb 10 08:55:37 EST 2018


2018-02-09 16:26 GMT+01:00 Steve Ebersole <steve at hibernate.org>:

> I think constraints should be exported to the DDL when the mode is DDL or
> `hibernate.validator.apply_to_ddl == true`.  I'd personally say that `
> hibernate.validator.apply_to_ddl` still works with NONE - as y'all keep
> saying, mode is about in-memory callbacks.  In fact because of that, we
> should even consider:
>
>    1. droping DDL as an allowable mode
>    2. no longer allowing multiple values
>
> Sounds great. Exactly what I had in mind :)


> Additionally I'd say that AUTO maps to CALLBACK *as long as BV is
> available on the classpath.  As I understand it, using CALLBACK mode is
> supposed to cause an error when BV is not available on classpath.  AUTO
> would silently ignore that.
>

Exactly. That's why I recommend users to go with CALLBACK over AUTO.

WDYT?
>

Seems we're on the same page. I can do this change, my only question would
be about dropping the DDL enum member and rejecting multiple values (your
1. and 2. above). Should we first (i.e. in 5.3) deprecate the enum member
and log a warning if multiple values are given?


>
> On Fri, Feb 9, 2018 at 9:14 AM Gunnar Morling <gunnar at hibernate.org>
> wrote:
>
>> Ok, so the constraints would be added to DDL when "hibernate
>> .validator.apply_to_ddl" is true and validation mode is one of {AUTO,
>> CALLBACK, DDL}. And they wouldn't be added to the DDL if "hibernate
>> .validator.apply_to_ddl" is false or validation mode is NONE?
>>
>> That'd work for me.
>>
>> 2018-02-07 21:07 GMT+01:00 Steve Ebersole <steve at hibernate.org>:
>>
>>> No, I think you are right and `hibernate.validator.apply_to_ddl` should
>>> apply to CALLBACK as well.
>>>
>>> On Wed, Feb 7, 2018 at 1:45 PM Gunnar Morling <gunnar at hibernate.org>
>>> wrote:
>>>
>>>> > How is a String "CALLBACK,DDL" considered "multiple values" to an
>>>> XSD?
>>>>
>>>> I was referring to the dedicated <validation-mode> element, which is
>>>> restricted to the values AUTO, CALLBACK, NONE in that XSD and which
>>>> can be given at most once [1]. I can see though how it'd work with the
>>>> javax.persistence.validation.mode String property.
>>>>
>>>> So, yeah, technically no change needed. Still quite subtle and very
>>>> easy to miss. Waiting a bit for some more feedback by others, if we decide
>>>> to leave it as is, we need at least to update the HV docs to describe this
>>>> in more depth (we only mention <validation-mode> but not that string
>>>> property).
>>>>
>>>> [1] https://github.com/hibernate/hibernate-orm/blob/
>>>> master/tooling/metamodel-generator/src/main/xsd/
>>>> persistence_2_1.xsd#L326-L339.
>>>>
>>>> 2018-02-07 20:05 GMT+01:00 Steve Ebersole <steve at hibernate.org>:
>>>>
>>>>> How is a String "CALLBACK,DDL" considered "multiple values" to an XSD?
>>>>>
>>>>> Look, I don't mind revisiting a change here.  I really have no horse n
>>>>> this race - this is not even my code originally.  TBH I thought this was
>>>>> code that you did.  So I don't mind changes here if there is a consensus.
>>>>> But let's use real reasons ;)
>>>>>
>>>>> On Wed, Feb 7, 2018 at 12:53 PM Gunnar Morling <gunnar at hibernate.org>
>>>>> wrote:
>>>>>
>>>>>> Right, giving multiple values isn't allowed as per JPA's XSD.
>>>>>>
>>>>>> 2018-02-07 19:44 GMT+01:00 Steve Ebersole <steve at hibernate.org>:
>>>>>>
>>>>>>> Of course you can.  `mode = CALLBACK,DDL`
>>>>>>>
>>>>>>> You mean that you cannot using single-valued setting
>>>>>>>
>>>>>>> On Wed, Feb 7, 2018 at 12:02 PM Gunnar Morling <gunnar at hibernate.org>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> 2018-02-07 16:08 GMT+01:00 Steve Ebersole <steve at hibernate.org>:
>>>>>>>>
>>>>>>>>> Ok, so this is the crux then because it really comes down to
>>>>>>>>> whether you
>>>>>>>>> believe whether it is valid to *only* export the annotation-based
>>>>>>>>> validations as DDL.
>>>>>>>>>
>>>>>>>>> And keep in mind that this code is basically unchanged from all
>>>>>>>>> the way
>>>>>>>>> back to the initial "integrations" with HV.  So back then the
>>>>>>>>> thought-process (not mine, btw) was that yes, that *is* valid -
>>>>>>>>> hence the
>>>>>>>>> option to chose just DDL as an option.
>>>>>>>>>
>>>>>>>>
>>>>>>>> You'd still have that ability with my suggestion, just keep
>>>>>>>> validation mode to NONE and set hibernate.validator.apply_to_ddl =
>>>>>>>> true.
>>>>>>>>
>>>>>>>> By "safest mode" above I meant CALLBACK is the right way if you
>>>>>>>> really want to make sure that lifecycle validation occurs, or you'll get an
>>>>>>>> exception if no BV provider is present. It can't happen that lifecycle
>>>>>>>> validation silently, unexpectedly doesn't happen. Hence I prefer it over
>>>>>>>> AUTO. And as things stand I can't benefit from constraints in DDL export in
>>>>>>>> that case, which is a pity.
>>>>>>>>
>>>>>>>> But if thats now no longer valid then that changes things.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Tue, Feb 6, 2018 at 3:15 PM Guillaume Smet <
>>>>>>>>> guillaume.smet at gmail.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>
>>>>>>>>> > Hi,
>>>>>>>>> >
>>>>>>>>> > On Tue, Feb 6, 2018 at 5:01 PM, Steve Ebersole <
>>>>>>>>> steve at hibernate.org>
>>>>>>>>> > wrote:
>>>>>>>>> >>
>>>>>>>>> >> Is it valid for a user to want *just* DDL-based validation?
>>>>>>>>> How would
>>>>>>>>> >> that
>>>>>>>>> >> work in Gunnar's request?
>>>>>>>>> >>
>>>>>>>>> >
>>>>>>>>> > From your writings, I suspect I'm the only one with this opinion
>>>>>>>>> but my
>>>>>>>>> > answer would be: "not if you use Bean Validation annotations".
>>>>>>>>> >
>>>>>>>>> > If you use BV's @NotNull, you expect BV to validate the input.
>>>>>>>>> And you
>>>>>>>>> > might want additional DDL in your database to be on the safe
>>>>>>>>> side (which
>>>>>>>>> > should be the default IMHO).
>>>>>>>>> >
>>>>>>>>> > --
>>>>>>>>> > Guillaume
>>>>>>>>> >
>>>>>>>>> _______________________________________________
>>>>>>>>> hibernate-dev mailing list
>>>>>>>>> hibernate-dev at lists.jboss.org
>>>>>>>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>>>>>>>
>>>>>>>>
>>>>>>
>>>>
>>


More information about the hibernate-dev mailing list