What do i get from setting this TransactionAttributeType.NOT_SUPPORTED
Asked Answered
O

1

7

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.

Omnipresent answered 29/5, 2012 at 9:10 Comment(0)
D
7

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).
Dingy answered 29/5, 2012 at 18:13 Comment(1)
How does the the EntityManager execute the query without a transaction? /confused/Mosasaur

© 2022 - 2024 — McMap. All rights reserved.