@Transactional method calling another method without @Transactional anotation?

前端 未结 4 1749
故里飘歌
故里飘歌 2020-12-02 05:16

I\'ve seen a method in a Service class that was marked as @Transactional, but it was also calling some other methods in that same class which were not marked as

4条回答
  •  粉色の甜心
    2020-12-02 05:30

    • Does that mean the call to separate methods are causing the application to open separate connections to DB or suspend the parent transaction, etc?

    That depends on a propagation level. Here are all the possible level values.

    For example in case a propagation level is NESTED a current transaction will "suspend" and a new transaction will be created ( note: actual creation of a nested transaction will only work on specific transaction managers )

    • What's the default behavior for a method without any annotations that is called by another method with @Transactional annotation?

    The default propagation level ( what you call "behavior" ) is REQUIRED. In case an "inner" method is called that has a @Transactional annotation on it ( or transacted declaratively via XML ), it will execute within the same transaction, e.g. "nothing new" is created.

提交回复
热议问题