设置此TransactionAttributeType.NOT_SUPPORTED会得到什么 [英] What do i get from setting this TransactionAttributeType.NOT_SUPPORTED

查看:340
本文介绍了设置此TransactionAttributeType.NOT_SUPPORTED会得到什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我不确定从中可以得到什么,但我碰巧发现了使用此构造的示例?

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

这是否意味着无状态EJB中的所有select语句

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();
    }

我从中得到什么?

谢谢。

推荐答案

得到的是:


  1. 一种相对正式的方式来告诉您的方法不需要事务(因此,您知道例如它不会在EntityManager中调用持久化,合并或删除)。

  2. 在某些情况下
  3. 可能性能优化。

    • 无需创建/传递交易。根据 Java EE 5教程:因为事务涉及开销,此属性可以提高性能。

    • 根据其他来源(例如Pro JPA 2),它提供了完全不创建 managed 实体(这是可能比立即创建分离的实体要重得多。)

  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).

这篇关于设置此TransactionAttributeType.NOT_SUPPORTED会得到什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆