br.exemplo.service.PessoaTesteTransactionService.java Source code

Java tutorial

Introduction

Here is the source code for br.exemplo.service.PessoaTesteTransactionService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.exemplo.service;

import br.exemplo.pojo.Pessoa;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
//import javax.transaction.Transactional;

/**
 *
 * @author root
 */
@ApplicationScoped
public class PessoaTesteTransactionService {

    @PersistenceUnit(unitName = "ExemploApplicationUnit")
    private EntityManagerFactory emf;
    //@PersistenceUnit
    //private EntityManager m;

    //@TransactionScoped()
    @Transactional(propagation = Propagation.SUPPORTS) //utiliza a mesma transao
    public void pessoasAll() {
        System.out.println("==== SELECIONA TODOS OS DADOS DA TABELA (2) ======");
        EntityManager m = emf.createEntityManager();
        List<Pessoa> list = m.createNamedQuery("Pessoa.all", Pessoa.class).getResultList();
        for (Pessoa p : list) {
            System.out.println("ALL >> " + p);
        }

    }

}