java - On transactions and event listeners -



java - On transactions and event listeners -

let me see if understand correctly. normally, should strive set operations belong 1 "unit of work" under same transaction, right? helps revert state of db in case of exception somewhere along chain of operations.

however, in particular case, have old service, not easy plug current code. hence have maintain running separately, , give rights same database current application stores data.

the problem comes when have insert new item db. have phone call service. if under 1 transaction, service start looking record in db, before transaction has committed. thus, started using event listeners, namely postinserteventlistener , postdeleteeventlistener.

now works ok, since transaction commits beforehand, totally disrupts code architecture. have built series of services inject each other, , have declare 2 listener classes. guess, best can create coordinator service implement 2 listener interfaces, in way totally couple hibernate, right?

in general, using listeners right way cases mine?

i don't see how came "i need have transaction committed before calling external service" "i decided using listeners".

why don't have next code:

public void somenontransactionalmethod() { sometransactionalservice.insertthingsindatabase(); externalservice.foo(); }

or

public void somemethod() { sometransactionalservice.insertthingsindatabase(); externalservice.foo(); }

where insertthingsindatabase uses requires_new propagation type?

java hibernate spring transactions

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -