Hello
I am having a web applicaion using JPA for CRUD Operations .
I have defined a Template class for creating and closing EntityManager as shown below :
I have a servlet and want to access EntityManager in it .
So for this i am calling createEntityManager() of Controller .
No..It is not write way to create EntityManager Object in servlet. Its Throw Exception because em is based on EJB Container So create the EJB project used it. Its a right way...Hope you understand
if we use EntityManager in EJB..
the instance of EntityManager managed by EJB Container, and so we don't have to deal to open/close the connection and EntityManager..
if you use Spring, then we are forced to write the Util class to deal with the instance of EntityManager..
its used in local transaction...
there are two kinds of transaction, namely Local transaction and Global Transaction..
and there are two kinds transaction management in EJB, namely Container Manage Transaction (CMT) and Bean Manage Transaction...
the Local Transaction involve only one resource (in this instance its involve 1 database)
the Global Transaction involve several resources (in this instance its involve 1/more database, JMS, and etc)..
you could inject JTA through UserTransaction in EJB for handle transactions..
Post by:autobot
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
a bit of art, as a gift, the permaculture playing cards