2 Replies Latest reply on Nov 30, 2007 8:07 AM by Pete Muir

    Using EntityManager out of EJBs components

    Maykell Frometa Newbie

      Hi all, i need to use EntityManagerFactory y EntityManager outside of an EJB, in fact i need to use them inside of a simple Pojo. The below class is a simple pojo that load a collection from the DB and return that collection in form of StecItem[] array. Now when i run this code i get the following error:

      java.sql.SQLException: You cannot set autocommit during a managed transaction!
      at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWrapperManagedConnection.java:482)

      Any help will be appreciated.

      public class CargaNomencladores {

      public static SelectItem[] cargaNomenclador(String nomencladorClassName)

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("jsfTest");
      EntityManager em = emf.createEntityManager();
      Query query = em.createQuery("select n from " + nomencladorClassName + "n");
      List tempNomencladorRl = query.getResultList();
      int size = tempNomencladorRl.size();
      SelectItem[] nomencladorSelectItem = new SelectItem[size];
      for (int i=0; i<size;i++){
      SelectItem si = new SelectItem(tempNomencladorRl.get(i),tempNomencladorRl.get(i).getValor());
      nomencladorSelectItem= si;
      return nomencladorSelectItem;