Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Spring Boot REST · property causing NullPointerException

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.

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

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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic