I'm working on a system's back end that uses Spring Boot, REST, HATEOAS, Hibernate and PostgreSQL. In order to use validation that works both in front end and back end calls without having to call validation methods manually, I'm using ConstraintValidator and @Constraint based validation. To make it work for removals too, which is not default, I had to add in application.properties.
The problem is that this addition started causing a NullPointerException when I try to delete an entity containing a list of the same type as a member. Simpler entities get deleted just fine. I even removed all validations, but it changes nothing.
Here's a project that's a non operational subset of the project I'm working on, here's the maven dependency tree, and here's the stack trace.
Please help me make it work.
Thanks in advance.
Guilherme Alan Ritter
posted 2 years ago
I found the solution (sort of). Actually, I didn't just included that property. It's the removal of the org.springframework.validation.Validators that caused the javax.validation validators to stop working. I found out that I needed to have a org.springframework.validation.Validator registered with the before|afterCreate|Save|LinkSave|Delete events and that I had to either call the complex entity's linked entity getter or change it's fetch = FetchType.LAZY to fetch = FetchType.EAGER.
My colleague gave me the suggestion when I mentioned that the NPE happens at a Hibernate code line that reads (see top of stack trace).
Doesn't look like the right way of doing things, but it's working for now. If someone has something to add, I'll be grateful.
Remember to always leap before you look. But always take the time to smell the tiny ads: