1 Reply Latest reply on May 27, 2010 12:57 AM by Sergio Samayoa

    Simple JSF2 + CDI + JPA + GlassFish 3 dont work

    Sergio Samayoa Newbie
      Im doing some very simple test with JSF2 + CDI + JPA + GlassFish 3, this is my backing bean:

      package test;

      import java.io.Serializable;

      import javax.enterprise.context.RequestScoped;
      import javax.inject.Named;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import entidad.Cliente;

      @Named
      @RequestScoped
      public class Test1 implements Serializable {

           private static final long serialVersionUID = -8891397705401579378L;

           public String getHolaMundo() {
                System.out.println("getHolaMundo()");
                return "Hola Mundo !!";
           }
           
           @PersistenceContext(unitName="test1") EntityManager em;

           public void crearCliente() {
                System.out.println("crearCliente() " + em.toString());
                Cliente c = new Cliente();
                c.setId(0);
                c.setNombre("Hola mundo !!");
                c.setSaldo(100);
                em.persist(c);
                em.flush();
           }
      }

      With a button in a JSF page I invoke "crearCliente()" but I get javax.persistence.TransactionRequiredException

      Do I have to use EJB instead of pojo for backing bean?

      What Im missing?