Skip to content

Doc: @Transactional on private methods with aspectj mode [SPR-13843] #18416

Closed
@spring-projects-issues

Description

@spring-projects-issues

Xiaolong Zuo opened SPR-13843 and commented

I would like to use @Transactional to private method.I find a way from springdocs 16.5.9,but it's unavailable.

My spring config file like below:

.....
<bean id="tx" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="tx" mode="aspectj" />
.....

My service class like below:

@Service
public class AdminUsAccountService {

    @Autowired
    private UsAccountMapper usAccountMapper;

    public void out() {
        UsAccount usAccount1 = new UsAccount();
        usAccount1.setId(1);
        usAccount1.setType(1);
        usAccountMapper.updateByPrimaryKeySelective(usAccount1);
        inner();
    }

    @Transactional
    private void inner() {
        UsAccount usAccount2 = new UsAccount();
        usAccount2.setId(3);
        usAccount2.setType(1);
        usAccountMapper.updateByPrimaryKeySelective(usAccount2);
        throw new RuntimeException();
    }
}

I expect the usAccount1's type is 1 and the usAccount2's type is 0(original value in db is 0),but all the two usAccount's type are 1.


Affects: 4.1.7

Backported to: 4.2.7

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions