[hibernate-dev] ValidationMode
Steve Ebersole
steve at hibernate.org
Fri Feb 22 17:45:06 EST 2013
See inline...
On Fri 22 Feb 2013 02:38:32 PM CST, Hardy Ferentschik wrote:
>
> On 22 Jan 2013, at 9:17 PM, Steve Ebersole <steve at hibernate.org> wrote:
>
>> Kind of. What I mean is that the HEM integration code is allowing Set <ValidationMode>. So our impl allows a value like "auto, ddl" or other combos. I am not able to grok why we allow multiples.
>
> I think this is a Hibernate specific "feature" to support also ddl generation. The idea is to say something like "callback,ddl" to enable validation and application of DDL constraints.
> Emmanuel might know more. With JPA 2.1 and the DDL stuff part of the spec I would assume there are are other explicit options to enable/disable these features.
Ok, for some reason I thought DDL-based validation was a JPA option as
well. But you are correct, it isnt. However, I still do not see the
benefit of allowing multiple selections simultaneously. is it really
such a great idea to allow callback *and* ddl in combination? We
already throw exceptions on other combinations.
Also, JPA 2.1 says nothing about DDL-based validation.
>> Also auto and callback are slightly different. callback causes an error if no bv provider is available whereas auto then skips validation.
>
> Hmm, seems wrong indeed, but maybe that's the difference in the end. Looking at "3.6.1.1 Enabling Automatic Validation" of the spec for the auto mode it is not explicitly mentioned
> that an exception should be thrown whereas for callback it is. Whether this is international or just badly written I don't know. Maybe something to clarify in the spec.
> Don't we have someone in the JPA expert group ;-)
Quoting part of 3.6.1.1:
<quote>
If the auto validation mode is specified by the validation-mode element
or the javax.persis-
tence.validation.mode property, or if neither the validation-mode
element nor the
javax.persistence.validation.mode property is specified, and a Bean
Validation provider
is present in the environment, the persistence provider must perform
the automatic validation of entities
as described in section 3.6.1.2. If no Bean Validation provider is
present in the environment, no lifecy-
cle event validation takes place.
</quote>
The first part of that first sentence is an overly complex grammatic
structure (imo) which is maybe why you missed it. But essentially the
sentence says that in AUTO validation mode (either explicit or implicit
due to no explicit value):
a) if "a Bean Validation provider
is present in the environment, the persistence provider must perform
the automatic validation of entities
as described in section 3.6.1.2"
b) If no Bean Validation provider is present in the environment, no
lifecy-
cle event validation takes place.
Again that is the auto case.
And then:
<quote>
If the callback validation mode is specified by the validation-mode
element or the javax.per-
sistence.validation.mode property, the persistence provider must
perform the lifecycle event
validation as described in section 3.6.1.2. It is an error if there is
no Bean Validation provider present in
the environment, and the provider must throw the PersistenceException
if the javax.per-
sistence.validation.mode property value "callback" has been passed to
the Persis-
tence.createEntityManagerFactory method
</quote>
So the only difference between CALLBACK and AUTO is in how they handle
Bean Validation provider "being not present".
More information about the hibernate-dev
mailing list