So I was working with JPA and transactions.
Consider the following:
In bean 1, with implicit TX 1, managed entities are loaded/created,and returned
in bean 2, with implicit TX 2, entities are modified
in bean 3, with NO TX, bean 1 is called, and the results are passed to bean 2.
and bean 4 is similar to bean 3, but with it's own transaction, TX3
What happens when bean 3 finishes: are the entities updated?
What happens when bean 4 finishes, are the entities updated?
The answer to this is simple; entities are managed through a persistance context. That context is tied to the transaction. So in bean 2, there is a difference. When called from bean 3, it runs in a different transaction then bean 1, and thus a different persistance context, and thus the entities are not managed 'by this transaction'.When called from bean 4, it all runs in the same transaction, TX3, and the results are persisted.
Consider the following:
In bean 1, with implicit TX 1, managed entities are loaded/created,and returned
in bean 2, with implicit TX 2, entities are modified
in bean 3, with NO TX, bean 1 is called, and the results are passed to bean 2.
and bean 4 is similar to bean 3, but with it's own transaction, TX3
What happens when bean 3 finishes: are the entities updated?
What happens when bean 4 finishes, are the entities updated?
The answer to this is simple; entities are managed through a persistance context. That context is tied to the transaction. So in bean 2, there is a difference. When called from bean 3, it runs in a different transaction then bean 1, and thus a different persistance context, and thus the entities are not managed 'by this transaction'.When called from bean 4, it all runs in the same transaction, TX3, and the results are persisted.
Reacties
Een reactie posten