Video Script
Video Script
Conclusion: we are calling addemployee method two times from main method
from main method we are calling add method Two times
for each method calling new transaction begin and insert query execute. for each
method calling new persistence context created. once transaction complete its
destroyed.
If we want to share state of entity across the Transactions and method call, we
need to use extended persistence context. persistence context created first
method call and transaction, Transactions and method calls done later share
same persistence context.
Show result: -
Conclusion:as we can see in the result. Database hit only one Time and both
methods share same persistence context. The data to fetch already managed in
persistence context.