Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do i get from setting this TransactionAttributeType.NOT_SUPPORTED

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.

like image 942
Mark Estrada Avatar asked May 29 '12 09:05

Mark Estrada


1 Answers

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).
like image 178
Mikko Maunu Avatar answered Dec 25 '22 20:12

Mikko Maunu