Skip to content

Instantly share code, notes, and snippets.

@hkakutalua
Created July 19, 2020 04:57
Show Gist options
  • Save hkakutalua/089e7816ab98b63fcbd4166d906ef7ec to your computer and use it in GitHub Desktop.
Save hkakutalua/089e7816ab98b63fcbd4166d906ef7ec to your computer and use it in GitHub Desktop.
LazyInitializationException
val product = productsRepository.findByIdOrNull(cartItem.productId)
if (product == null) {
return ResponseEntity.notFound().build()
}
val cart = cartsRepository.findByIdOrNull(cartId)
if (cart == null) {
return ResponseEntity.notFound().build()
}
cart.addProduct(product, cartItem.quantity)
cartsRepository.save(cart) // with @Transactional there's no need of this line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment