2 Replies Latest reply on Dec 23, 2009 11:42 AM by Sergey Vidyuk

    EntityManager is not injected in Conversation scope component

    Sergey Vidyuk Newbie


      I have an issue with one of my components. I'm annotating EntityManager member with In but it's not injected. This component is created to provide server side pagination for rich:dataTable and first call of a function which tries to access entityManager comes not from JSF action.

      I have generic implementation of serializable data model:

      public class GenericDataModel<Item> extends SerializableDataModel implements Modifiable {
         private DataProvider<Item> dataProvider;
         public setDataProvider(DataProvider<Item> dataProvider) {
            this.dataProvider = dataProvider;
         // All abstract method from SerializableDataModel and Modifiable

      Where DataProvider is the following interface:

      public interface DataProvider<Item> {
           public List<Item> findItems(int firstRow, int numberOfRows, String sortField, Ordering ordering);
           public Integer getItemId(Item item);
           public Item getItemById(Integer pk);
           public Integer countItems();

      And my component itself:

      public class StudentList implements DataProvider<StudentListItem>,Serializable {
         private static final long serialVersionUID = 1L;
         @In EntityManager entityManager;
         @Logger Log log;
         private GenericDataModel<StudentListItem> dataModel;
         public StudentList() {
            dataModel = new GenericDataModel<StudentListItem>();
         public Integer countItems() {
            if ( entityManager == null ) {
               entityManager = (EntityManager)Component.getInstance("entityManager");
               log.error("Seam dosen't injected entityManager");
            Long count = (Long)entityManager.createQuery("select count(s) from Student s").getSingleResult();
            return count.intValue();
         // Other abs methods from DataProvider interface

      I've added check if entityManager is null everywhere it's used to fix the problem. According to the logs first call of function which needs entityManager is call of countItems() function and at this moment entityManager is not yet injected. Does anybody know better solution for this issue?