We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Apologies. This issue may be just a question.
I have an entity with a lazy-fetch -to-one attribute.
@MappedSuperclass abstract class MappedParent { @NotNull private String a; } @MappedSuperclass abstract class MappedChild<PARENT extends MappedParent> { @NotNull @Basic(optional = false) @Column(name = "parent_id", nullable = false, insertable = true, updatable = false) private Long parentId; @Valid // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @NotNull @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "parent_id", nullable = false, insertable = true, updatable = false) private <PARENT> parent; } @Entity class Parent extends MappedParent { } @Entity class Child extends MappedChild<Parent> { }
When I, in my test code, select one and assure that the entity is valid, the framework (or library) tries to validate fields on.
@Transactional @SpringBootTest class SomeTest { @Autowired private EntityManager entityManager; void () { final var found = entityManager.find(...) BeanValidationTestUtils.requireValid(selected); // <<<<<<<<<<<<<<<<<<<<<<< }
The BeanValidationTestUtils.requireValid(selected); looks like this. Nothing's special.
BeanValidationTestUtils.requireValid(selected);
public static <T> Set<ConstraintViolation<T>> validate(Validator validator, final T object, final Class<?>... groups) { Objects.requireNonNull(validator, "validator is null"); Objects.requireNonNull(object, "object is null"); Objects.requireNonNull(groups, "groups is null"); return validator.validate(object, groups); } public static <T> T requireValid(final Validator validator, final T object, final Class<?>... groups) { final var violations = validate(validator, object, groups); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } return object; }
The moment just before validating the entity looks like this.
selected = (Child ...) parent_id = xx parent = (Parent@HibernateProxy@nnnn; a=<real, not-null>, b = <real; not-null>) $$_hibernate_interceptor a = null b = null
And the validation fails tries to validate parent.a.
parent.a
parent.a: must not be null,
When I comment-out the @Valid annotation, leaving the @NotNull annotation, it passes.
@Valid
@NotNull
//@Valid // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @NotNull @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "parent_id", nullable = false, insertable = true, updatable = false) private <PARENT> parent;
The text was updated successfully, but these errors were encountered:
This has really nothing to do with Spring Data, but seems to be about Hibernate Validator.
Sorry, something went wrong.
No branches or pull requests
Apologies. This issue may be just a question.
I have an entity with a lazy-fetch -to-one attribute.
When I, in my test code, select one and assure that the entity is valid, the framework (or library) tries to validate fields on.
The
BeanValidationTestUtils.requireValid(selected);
looks like this. Nothing's special.The moment just before validating the entity looks like this.
And the validation fails tries to validate
parent.a
.When I comment-out the
@Valid
annotation, leaving the@NotNull
annotation, it passes.The text was updated successfully, but these errors were encountered: