In my Spring Boot application generated with JHipster (v6.0.1) Kotlin blueprint (v0.8.0) I have the following POST request handler
@PostMapping("/book")
fun createBook(@RequestBody createBookVM: CreateBookVM): ResponseEntity<Book> {
val author = authorRepository.getOne(createBookVM.authorId)
val userLogin = SecurityUtils.getCurrentUserLogin().orElseThrow { RuntimeException("User not logged in") }
val user = userRepository.findOneByLogin(userLogin).orElseThrow { RuntimeException("IMPOSSIBLE: user does not exist in DB") }
val book= Book()
book.author = author // FIXME
book.user = user
log.debug("Author object with id : {}", author.id) // THIS WORKS
val result = bookRepository.save(book)
return ResponseEntity.created(URI("/api/books/" + result.id))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.id.toString()))
.body(result)
}
The problem is that the author
is not added to the book
(book.author
will be null
). However, I can access the values of author
as shown with the logging statement. Adding user
to book
also works fine.
I suppose the problem is that authorRepository.getOne(createBookVM.authorId)
returns a proxy object, not an instance of Author
, but I do not know how to cope with this situation.