Announcement Announcement Module
No announcement yet.
not to create new transaction for some methods Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • not to create new transaction for some methods

    I use @Transaction to my service classes this way all methods will be wrapped with transaction required by default , some of my methods does not need transaction for these methods I annotated with

    @Transactional(readOnly=true, propagation=Propagation.SUPPORTS)
    is this right ?

  • #2
    I don't know if it's "right". I would assume a read-only transaction would be lighter-weight than a read-write transaction, but if you really want to avoid creating any transaction at all for those methods, then you should probably only put the "@Transactional" annotation on the methods you want to be transactional.


    • #3
      I guess it is OK. The strategy may depend on how many methods need to have REQUIRED and how many does not need transaction.
      - if almost all requires TX it may be usefull to annotate with REQUIRED on a class level (cleared than annotating all methods) and only annotate the methods that are exceptions to this rule with SUPPORTS
      - if majority does not require TX do like Dkarr wrote. Annotate only these that requires with REQUIRED and leave other without annotations

      One thing that comes to my mind is how readOnly=true is used with SUPPORTS. What happens when TX SUPPORTS method with readOnly=true is invoked inside "read-write" transaction. I guess it will not change anything and is not relevant. Am I write?