Skip to content

alampada/pg-spring-r2dbc-transactional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transactional annotation for spring r2dbc.

  1. Run launch-db.sh to start a container running postgres.
  2. Start the spring application (update application.yml with the container ip if needed).
  3. Endpoint to hit http://localhost:8080 (POST without body).
  4. Check contents of db by using postgres docker docker run --rm -it postgres psql -h 172.17.0.2 -U postgres. Password is postgres.
  5. Expected behaviour. Table a should have a single row and table b should be empty.

Project Structure

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.

Behaviour observed:

  • Annotate the method in DemoController with @Transactional. As expected, the service returns 500 and no rows are added to table b.
  • Annotate DemoService.doSomething() with @Transactional. As expected, the service returns 500 and no rows are added to table b.
  • Annotate DemoService.internal() with @Transactional. Transaction doesn't seem to work, a row is added to table b.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published