Where to place @Transactional annotation in Play

后端 未结 1 431
抹茶落季
抹茶落季 2020-12-18 12:10

I am trying to connect my Play application with a database, I am following controller->service->DAO layer style.

Where should the @Transactional annotation be placed

相关标签:
1条回答
  • 2020-12-18 13:00

    I would recommend not to use @Transactional because it wraps entire action in an JPA transaction. It would be more efficient to start the transaction closer to db call.

    I prefer starting the transaction at service level. Also it is important to note that db call is a blocking process so it must be executed outside of default action context.

    Take a look at simple DAO+Service example https://gist.github.com/dzagorovsky/b8064c97ba647ed453ab

    Also read about play thread pools here https://www.playframework.com/documentation/2.4.x/ThreadPools#Using-other-thread-pools

    Blocking code (db calls) handling described here: https://www.playframework.com/documentation/2.3.x/JavaAsync

    0 讨论(0)
提交回复
热议问题