I have 2 spring bean (Bean A and B) which access the db. Both bean are in PROPAGATION_REQUIRED_NEW and the isolation level is READ COMMITED on a ORACLE db.
Bean call A select (via Hibernate) on the same table twice with different criteria. Then the bean B is called to for each of the row oth the table to do an update on them. Weirdly everything work fine if Bean A does only one call (select) to the db. I've check with the query from dba.stackexchange and it's only when the second "select" in Bean A that have a db lock.
NOTE: Why not using PROPAGATION_REQUIRED or PROPAGATION_NESTED for bean B ? We don't use PROPAGATION_REQUIRED Because we don’t won’t to roll back everything if one of the row fail and has for PROPAGATION NESTED the version of our jdbc driver we are using doesn’t support it.
My current workaround is to have a bean that handle the select seperatly and the main bean doesn't do any transaction just call the two other bean. I just find it really strange that doing "select * from X" cause a lock on the table when we provide locking NONE and we are in READ_COMMITED. Am I missing something here?
The first query:
select
temptable0_.ID as ID1_43_,
temptable0_.IDSEND as IDS2_43_,
temptable0_.DATERECEI as DAT3_43_,
temptable0_.DATEPROC as DAT4_43_,
temptable0_.STATUT as STA5_43_,
temptable0_.ERROR_TYPE as ERR6_43_,
temptable0_.CODE as COD7_43_,
temptable0_.DESCRIPTION as DES8_43_,
temptable0_.NOTIF as NOT9_43_,
temptable0_.ACTION as ACT10_43_,
temptable0_.IDCLIENT as IDC11_43_,
temptable0_.PARAM as PAR12_43_
from
TABLE_TMP temptable0_
where
temptable0_.STATUT in (
'NEW'
)
The second query (same transaction (BEAN A))
select
temptable0_.ID as ID1_43_,
temptable0_.IDSEND as IDS2_43_,
temptable0_.DATERECEI as DAT3_43_,
temptable0_.DATEPROC as DAT4_43_,
temptable0_.STATUT as STA5_43_,
temptable0_.ERROR_TYPE as ERR6_43_,
temptable0_.CODE as COD7_43_,
temptable0_.DESCRIPTION as DES8_43_,
temptable0_.NOTIF as NOT9_43_,
temptable0_.ACTION as ACT10_43_,
temptable0_.IDCLIENT as IDC11_43_,
temptable0_.PARAM as PAR12_43_
from
TABLE_TMP temptable0_
where
temptable0_.STATUT in (
'ERROR'
)
And the Update statement (done by BEAN B)
update
TABLE_TMP
set
IDSEND=?,
DATERECEI=?,
DATEPROC=?,
STATUT=?,
ERROR_TYPE=?,
CODE=?,
DESCRIPTION=?,
NOTIF=?,
ACTION=?,
IDCLIENT=?,
PARAM=?
where
ID=?
Where IDSEND is incremented, DATEPROC is set and STATUT and ERROR_TYPE are set if there a error or a success.