79459567

Date: 2025-02-22 12:05:39
Score: 1
Natty:
Report link

Problem was that users were initialized with their books property being null. So, even though in one of my numerous attempts to fix it, my bookController's post mapping looked exaclty like this:

if (!book.getAuthors().isEmpty()) {
    for (Users author : book.getAuthors()) {
        author.setRole(Roles.AUTHOR);
        author.addBooks(Set.of(book)); // bidirectional link wasn't 
                                       //working cause Users.books = null
        userService.saveUser(author);
    }
}
bookService.saveBook(book);

it didn't seem to work because it was trying to addBooks to null instead of a Set of books and I never got an error because it was caught in a try catch statement. Thank you so much. Without the answer that pointed me to the right direction, I never would have found id!

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: marioszap