Home > Enterprise >  Java/Spring-boot: Transactional database update problems
Java/Spring-boot: Transactional database update problems

Time:10-16

I'm currently working on my react skills by building some simple projects. Today I decided to build a todo app and needed to write a quick backend(in spring cause why not lmao). Everything went fine as usual(I follow amigos code's spring boot tutorial 2022 pattern from youtube to design the backend) until I tried testing the API with postman and I realized that everything works fine but the put/update method. In more detail, whenever I call the put method of the API my object gets updated inside the scope but its not persistent in the database.

Source code is hosted on gh: React-todo-backend

I got a rest api put method that calls my service put method to update its members.
(Controller:put->Service:put->Entity.setVariables(variables))

What I tried:

  • Adding @Transactional annotation above my put method in my service class(used to work I'm not quite sure if new version of spring changed anything.)
  • I thought of maybe deleting the entity and saving it as new in the database but my id is auto-generated and unique so I'm probably not gonna follow this approach since I don't want to alter the data myself(instead of the user).

Thanks for your time and help in advance :)
(Its also my first time posting on stackoverflow so and I tried following the rules as much as possible but in case I missed anything please let me know and I'll try to fix it as soon as possible.)

  • Windows 11, JDK 17, Spring 2.7.4, Mysql

CodePudding user response:

I looked your github project and realized that you didn't use save() method of repository to save your ToDo, use todoRepository.save(todoOptional) in TodoService -> putTodo. If you dont save your changes, row will not be updated that you want to update.

  • Related