0% found this document useful (0 votes)
6 views5 pages

Video Script

The document discusses transaction management in Spring ORM using both XML and Java configuration, highlighting the use of annotations like @Transactional and @PersistenceContext for managing transactions and entity managers. It explains the differences between transactional scoped and extended persistence contexts in an employee management application, demonstrating how they affect database interactions. The conclusion emphasizes the efficiency of using an extended persistence context to share entity states across multiple transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Video Script

The document discusses transaction management in Spring ORM using both XML and Java configuration, highlighting the use of annotations like @Transactional and @PersistenceContext for managing transactions and entity managers. It explains the differences between transactional scoped and extended persistence contexts in an employee management application, demonstrating how they affect database interactions. The conclusion emphasizes the efficiency of using an extended persistence context to share entity states across multiple transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

For joining:--

I'm honored to be part of this team.


Thank you for thinking of me to work on this with you.
I'm grateful for this opportunity to collaborate.
I hope to learn a lot from this privilege.
Thank you for inviting me to join your team.
Thanks to Vijay and Raghavendran sir.

Script for Spring ORM Transaction Management: -


We will see transaction management with xml configuration. Here I have an
example. in this we could check Employee bean and Entity classes in bean and
entity packages, and we could check service and dao implementation classes in
service and dao package. in dao implementation class we annotate class with
@Transcational Annotation so spring orm will begin and commit transaction
automatically, so we need not call begin and commit method manually.
we inject entity manager with the help of @persistenceContext annotation, so we
need not to create entity manager manually. spring orm will manage entity
manager creation.
configurations files we have written in resources package here we have
connection properties file where we have written information about database
connection. In jpa-config xml file we have configured entity manager factory
bean . for configuring Transaction management we need to instantiate
JpaTransaction manager bean by injecting entity manager factory and create a
custom Transaction manager txmanager . for enabling custom transcation
manager we need to provide it in tx: annotation element by assigning tx manager
to transaction manager property. Now we can execute the application and check
the result
For java configuration
We will see transaction management with java configuration. Here I have an
example application . in this application . we could check Employee bean and
Entity classes in bean and entity packages, and we could check service and dao
implementation classes in service and dao package. in dao implementation class
we have to annotate with @Transcational Annotation and in the value property
we have to assigned custom transcation manager txmanager . so Transcation can
begin and commit automatically and we need not call begin and commit method
manually.
we inject entity manager with the help of @persistenceContext annotation, so we
need not to create entity manager manually. spring will manage entity manager
creation with the help of persistence context annotation
For managing configurations, we have written springdbconfig class in config
package. we have annotated. We have to annotate class with
@EnableTransactionManagent Annotation . this annotation is equivalent to tx
annotation driven xml element . here @value annotation read value from
properties file and giving to the data source. With the help of @bean annotation
we instantiate configuration bean which is equivalent to bean xml element . for
creating custom transaction manager we need to instantiate jpa Transaction
manager bean by passing entity manager factory as a constractor argument in
Jpa trascation manger contractor and we will assin the tx manage to the value
property of bean annotation

Types of persistence context Demo


in employee management application example, we will observe and configure
types of persistence context .in Transactional scoped persistence context which is
called container managed Entity manager .in this Type of persistence context ,for
every method call, a new transaction begins, and persistence context is created.
Same persistence context is used until method execution is completed.

Show Code: showing code and executing addemployee method in code.


Showing result: -

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 code: add type=PersistenceContextType.EXTENDED in


PersistenceContext annotation and execute main method.

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.

You might also like