Øyvind:
You can map your session id to the current transaction in SQL with:
select txid, sid
from sysmaster:sysrstcb as r
join sysmaster:systxptab as t
on t.owner = r.address and r.sid = dbinfo('sessionid');
However, as you have discovered, the transaction id for a given session is reused by that session and appears to be assigned to that session at connect time. Witness, no transaction started:
$ dbaccess art -
Database selected.
> select txid, sid
from sysmaster:sysrstcb as r
join sysmaster:systxptab as t
on t.owner = r.address and r.sid = dbinfo('sessionid');> > >
txid sid
42 90
1 row(s) retrieved.
>
begin work;
Started transaction.
> select txid, sid
from sysmaster:sysrstcb as r
join sysmaster:systxptab as t
on t.owner = r.address and r.sid = dbinfo('sessionid');> > >
txid sid
42 90
1 row(s) retrieved.
>
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com------------------------------
Original Message:
Sent: Thu September 04, 2025 04:52 AM
From: Øyvind Gjerstad
Subject: Getting current transaction ID
We are trying to debug an issue with transaction handling in Hibernate and JBoss. We want to see if a new transaction has been created in certain scenarios.
So I did some research if it was possible to get the current transaction ID in SQL, but found nothing.
But I did find the mi_get_transaction_id() internal function, so I then created a normal UDR on top of that:
create function get_transaction_id() returns int external name '(mi_get_transaction_id)' language C;
However, this simple script returns the same transaction ID twice, which I didn't expect.
begin; execute function get_transaction_id(); commit; begin; execute function get_transaction_id(); commit;
So, it looks like the transaction IDs are reused? If I run this again in a new session, I get a new ID, but again the same ID twice.
Any tips on how to find out whether a new transaction has been created? Since I'm mentioning JBoss, the language obviously is java, JDBC 9.40.JC9, engine version is 14.10.FC10
Thanks in advance
------------------------------
Øyvind Gjerstad
Developer/Architect
PostNord AS
------------------------------