Transaction Propagation with JDBI

297 views
Skip to first unread message

Govinda Sakhare

unread,
Nov 30, 2020, 12:37:33 PM11/30/20
to jDBI
Hi All,

I am calling a method that is marked with @Transaction from a method which itself is annotated with @Transaction.

I know how Spring's @transaction, has a propagation attribute, but how does it work in the case of JDBI? what is the default propagation level? How to change it if needed?

Thanks
Govinda

Patrick Lightbody

unread,
Nov 30, 2020, 2:18:46 PM11/30/20
to jd...@googlegroups.com
I'm also interested in the answer here. Also related, how does jdbi.useTransaction() relate.

My hunch is: that both withHandle() and inTransaction() ultimately just grab a connection from the pool and so if spring's stuff is in the mix it'll keep handing off the same Connection object (via ThreadLocal management) even for repeated calls, forcing all of them into the same logical transaction at the top-most @Transactional.

--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jdbi/fd0658fe-d316-46c3-9faa-c9c36689f73fn%40googlegroups.com.

Steven Schlansker

unread,
Nov 30, 2020, 2:41:07 PM11/30/20
to jd...@googlegroups.com
There's a brief treatment in the docs:

http://jdbi.org/#_transaction_management

Short version is, nested @Transaction with the same (or unspecified) isolation level may "join" a similar outer transaction.  Any isolation mismatch is a runtime error.  If an "inner" transaction aborts, so does the "outer" transaction.

There's no concept of parking a transaction and starting a separate inner transaction automatically at this time, although of course it's straightforward enough to do so manually with two Handles.

Matthew Hall

unread,
Nov 30, 2020, 2:49:09 PM11/30/20
to jd...@googlegroups.com
Please also note that the @Transaction annotation is not a Spring-style AOP annotation--you can't just slap it on any object. The only place where it does anything is on a SQL Object method.

-Matt

Reply all
Reply to author
Forward
0 new messages