Transactional annotation for spring r2dbc.
- Run
launch-db.sh
to start a container running postgres. - Start the spring application (update
application.yml
with the container ip if needed). - Endpoint to hit
http://localhost:8080
(POST without body). - Check contents of db by using postgres docker
docker run --rm -it postgres psql -h 172.17.0.2 -U postgres
. Password ispostgres
. - Expected behaviour. Table
a
should have a single row and tableb
should be empty.
When we hit the endpoint, the service attempts to try to add a row to table a
and a row to table b
.
Adding the row to table a
will with a duplicate key violation. Since the call is Transactional
no rows should be inserted to table b
.
- Annotate the method in
DemoController
with@Transactional
. As expected, the service returns 500 and no rows are added to tableb
. - Annotate
DemoService.doSomething()
with@Transactional
. As expected, the service returns 500 and no rows are added to tableb
. - Annotate
DemoService.internal()
with@Transactional
. Transaction doesn't seem to work, a row is added to tableb
.