1

I have a little problem when I want to save entity in other Thread. e.g.

Executors.newCachedThreadPool().submit(() -> userService.save(user))

and in userService I have a lot of logic and at the end I want to save user into database using userRepository.save(user) and repo doesn't save it. What am I doing wrong? If someone want more info let me know

Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
  • This is probably because transactions are bound to threads by default so your new Thread doesn't have a transaction. See https://stackoverflow.com/a/24917195/66686 – Jens Schauder Jul 21 '20 at 07:55
  • @JensSchauder I added Transactional annotation to my service class but it's still doesn't work – Mateusz Sobczak Jul 21 '20 at 09:39

0 Answers0