开发者

My persistenceManager is null

I have Interface which is defined as

@Local
public interface MyPersistenceManagerLocal {

  public List<PropertyList> getPropertyList(int id);

}

and implentaion class for above interface is

@Stateless
public class MyPersistenceManagerBean implements MyPersistenceManagerLocal {

  @PersistenceContext(unitName = PersistentSettings.PERSIST_NAME)
  private EntityManager entityManager;

  @Override
  public List<PropertyList> getPropertyList(int id) {
    System.out.println("inside MyPersistenceManagerBean.getPropertyList()");
    ......
    ......
    ......
  }
}

and i ma calling this 开发者_开发技巧in another call

@Stateless
public class ClientImpl implements Client {

  @EJB
  MyPersistenceManagerLocal persistenceManager;

  final List<PropertyList> dbList = persistenceManager.getPropertyList(id);

}

i am getting NullPointerException on

final List<PropertyList> dbList = persistenceManager.getPropertyList(id);

in debug mode i got persistenceManager is null.

i am new in EJB and JPA not able to solve this. any help why i am getting persistenceManager as null


You are getting NPE because container haven't injected the required bean yet. You need to set it in @PostConstruct method i.e.

@Stateless public class ClientImpl implements Client {

   @EJB MyPersistenceManagerLocal persistenceManager;

   private List dbList;
   @PostConstruct
   public void init(){
        dblist = persistenceManager.getDbList();
   }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜