Scofield Wang wrote:
thank you. I also verify this point, every invocation to a business method of stateless sesion beans will get a new entity manager instance.
Can I inject mutiple entity managers in stateless session bean to use them in a JTA transaction? it can work well?
Question 1: that fully depends on your transaction management scheme. If you design your methods such that transactions are adopted, then the entity manager and its persistence store are going to be adopted as well. But if you annotate a method to have its own isolated transaction (CREATE_NEW for example), then it will get its own EntityManager wrapped around that isolated transaction.
Question 2: Very good question. It shouldn't be a problem. I'm not 100% sure since I tend to isolate the management of a persistence unit to its own set of beans and not mix and mash. It keeps the application design simpler.
I would really advise you to get a good book on EJB tech to get a better feel for not only the technology but also the theory behind the technology. EJBs are deceptively easy to program but sadistically hard to properly apply with all the stuff that is going on under the hood.