What do i get from setting this TransactionAttributeType.NOT_SUPPORTED

对着背影说爱祢 提交于 2019-12-22 04:41:35

问题


I happen to find examples that uses this construct though I am not sure what can I get from this?

Does it means that all select statements in a stateless EJB should follow this?

@Stateless
public class EmployeeFacade {
    @PersistenceContext(unitName="EmployeeService")
    EntityManager em;

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<Department> findAllEmployees() {
        return em.createQuery("SELECT e FROM Employee e",
        Employee.class)
        .getResultList();
    }

What do I get from this?

Thanks.


回答1:


What you get is:

  1. Relatively formal way to tell that your method does not need transaction (as consequence you know for example that it will not call persist, merge or remove in EntityManager).
  2. Possible performance optimization in some cases.
    • No need to create/pass transaction. According Java EE 5 Tutorial: "Because transactions involve overhead, this attribute may improve performance."
    • According other sources (for example Pro JPA 2) it offers implementations possibility to not create managed entities at all (which is likely heavier operation than creating detached entities right away).


来源:https://stackoverflow.com/questions/10796172/what-do-i-get-from-setting-this-transactionattributetype-not-supported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!