[bv-dev] BVAL-234 @NotNull @Id for JPA and Bean Validation

Emmanuel Bernard emmanuel at hibernate.org
Tue May 15 07:25:48 EDT 2012



On 15 mai 2012, at 12:38, Hardy Ferentschik wrote:

> Is option #3 even possible within the JPA spec? One would need meta information about the id property 
> (which generation type and how exactly this type behaves regarding the id generation time). I don't think there
> is a way to do this with the JPA api. Also  JPA does not even explicitly define the behavior of the different strategies. 

Remember that the TraversableResolver used in pre-* events is implemented by the JPA provider itself. It's very easy for the implementation
to tap provider specific metadata (most likely not exposed). We don't need JPA to expose the API.

> 
> Disabling the validation per default can also backfire in the cases where a user "knows" that a certain strategy 
> will generate the id pre insert. In this case it would be valid to add @NotNull.

True but that would definitely make the application non portable from a JPA point of view.


More information about the beanvalidation-dev mailing list