Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction not work on DAO bean without an attachment. #2670

Open
puzatin opened this issue Apr 18, 2024 · 0 comments
Open

Transaction not work on DAO bean without an attachment. #2670

puzatin opened this issue Apr 18, 2024 · 0 comments

Comments

@puzatin
Copy link

puzatin commented Apr 18, 2024

    @Autowired
    private FooDao fooDao;
    @Autowired
    private BarDao barDao;
    @Autowired
    private Jdbi jdbi;
    
    public saveFooBar1() {
        jdbi.useTransaction(handle -> {
//            transaction not open
            long insertedId = fooDao.insert(new Foo()); 
            barDao.insert(new Bar(insertedId)); // open transaction because BarDao.insert() have @Transaction
        });
    }

    public saveFooBar2() {
        jdbi.useTransaction(handle -> {
            FooDao fooDao = handle.attach(FooDao.class);
            BarDao barDao = handle.attach(BarDao.class);
 //            transaction open
            long insertedId = fooDao.insert(new Foo());
            barDao.insert(new Bar(insertedId)); // transaction not open despite BarDao.insert() have @Transaction
        });
    }

in the case of saveFooBar1(), is this the expected behavior or am I doing something wrong?
I Expected behavior as in saveFooBar2() method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant