开发者

My persistenceManager is null

开发者 https://www.devze.com 2023-02-06 07:40 出处:网络
I have Interface which is defined as @Local public interface MyPersistenceManagerLocal { public List<PropertyList> getPropertyList(int id);

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

精彩评论

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