java bean validation 2.0 vs hibernate validator
Asked Answered
S

1

6

what is difference b/w java bean validation 2.0 and hibernate validator. is both are same or different. because both look like same. can you discuss differences between java bean validation 2.0 and hibernate validator.

which one should I use in my project?

Thanks

Scoville answered 2/4, 2018 at 6:24 Comment(3)
I am sure these are different. Because hibernate validators are applicable at DB query level as well while java bean validation not.Falls
Also, would you mind putting what you have tried so far?Falls
can you provide some those differences?Scoville
C
11

Bean Validation 2.0 is a Java specification called JSR-380 which defines the API.

The Bean Validation api jar, e.g. validation-api-2.0.1.jar, contains only interfaces / annotations etc, no implementations.

Hibernate Validator (6.0.1+) is the reference implementation, and currently the only certified implementation of JSR-380.

Java specifications (JSRs) are developed under the Java Community Process (JCP). In addition to delivering a formalised specification for an API, the JSR would often include a reference implementation but other vendors are free to provide their own implementation.

Compare this with the Java Persistence API (JPA) specification JSR-317. There are several different vendors with competing JPA implementations, including Hibernate, EclipseLink (the reference implementation for JSR-317), OpenJPA etc.

In the case of Bean Validation 2.0, there just are no competing implementations at present, just the reference implementation.

Circular answered 2/4, 2018 at 6:39 Comment(4)
are you say something like that SLF4j is specification log4j is implementation. so you can use SLF4j-Log4j combination for logging same for here: means we can use Bean Validation 2.0 - Hibernate Validator combination for validation purpose.Scoville
Similar, except that: 1) SLF4J is a facade where the slf4j-api jar contains an implementation that delegates to the appropriate logging framework, like an adaptor pattern. The Bean Validation api jar, e.g. validation-api-2.0.1.jar, contains only interfaces / annotations etc, no implementations. There is no delegation. 2) There is no standardised specification for SLF4J. So others cannot compete on implementation.Circular
you can put this also in answer: "The Bean Validation api jar, e.g. validation-api-2.0.1.jar, contains only interfaces / annotations etc, no implementations."Scoville
If validation API contains only the interface and annotations. If so adding a validation jar will not validate the fields. We need to add a reference implementation eg. and hibernate validation implementation to validate the fields. Am I right?Pictorial

© 2022 - 2024 — McMap. All rights reserved.