Im using
I have a lazy loadable Entity
@NotNull
@OneToOne(fetch = FetchType.LAZY,optional = false,cascade = CascadeType.PERSIST)
@JoinColumn(name="library_id")
private Library library;
public Library getLibray() {
return library;
}
and a defaultValidator
private final ValidatorFactory factory = Validation
.buildDefaultValidatorFactory();
private final Validator val = factory.getValidator();
When I am trying to validate unattached and attached Entitys annotated with @NotNull, @Size
and so forth.
Everything works fine. But when i load an Entity via Lazy Load and try to validate it.
The Validator fails every time. This seems due to the fact that im getting a Hibernate Proxy Object.
I can get arround this "issue" easily by just unproxying it.(But this is not so favorable in my situation)
Is this the expected behavior? Do I get the same behavior in OpenJPA, EclipseLink....?
Have a nice Sunday guys ;) I hope i did make the Question clear?
Bean validation is an optional feature in JPA 2, supported with its persistence provider. The persistence provider enables Bean validation on all entities to which annotations are applied. If Hibernate 3.5 is used as the persistence provider, then JPA 2 will use Hibernate Validator.
Hibernate validator specific annotations In addition to the constraints defined by the Bean Validation API, Hibernate Validator provides several useful custom constraints which are listed below. Checks that the annotated character sequence passes the Luhn checksum test.
Therefore, when Spring Boot validates the class instance, the constrained fields must be not null and their trimmed length must be greater than zero. Additionally, Bean Validation provides many other handy constraints besides @NotBlank.
Given below are the required hibernate validator maven dependencies. Bean validation allows expressions inside the error messages. To parse these expressions, we must add a dependency on both the expression language API and an implementation of that API.
Issue can be solved by annotating methods instead of fields.
This is further discussed in HVAL-13 issue and also in HV-535. If replacement of annotations is not feasible, solution suggested in bug report is using HibernateProxyValidator instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With