What is difference between @Resource UserTransaction and EntityManager.getTransaction()

前端 未结 3 1216
滥情空心
滥情空心 2020-12-13 06:31

Can anybody explain what is difference between :

@Resource
UserTransaction objUserTransaction;

and

EntityManager.getTransac         


        
3条回答
  •  我在风中等你
    2020-12-13 07:18

    UserTransaction refers to the JTA transaction entity. You will only be able to use this when there is a JTA module available in the application server: for example, if you're deploying an application with this on Tomcat (which by default does not support JTA), code relying on this will fail. This is default type of transaction used in EJB's and MDB's.

    EntityManager.getTransaction() retrieves a local transaction entity. This also sometimes known as a resource local transaction.

    Resource local transactions are very different from JTA transactions: among other things, resource local transactions are specific to a resource, whereas JTA transactions tend to be specific to a particular thread.

    For more information on the difference between resource local and JTA transactions, see this stackoverflow answer here: What is the difference between a JTA and a local transaction?

提交回复
热议问题