jboss EntityManager不能注入的解決辦法

1 try {
   InitialContext initialContext = new InitialContext();
   EntityManagerFactory lookup = (EntityManagerFactory) initialContext.lookup("java:/EntityManagerFactories/myData");
   entityManager = lookup.createEntityManager();
  } catch (NamingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 

2 類名前

@Stateless(name = "ejb/PropertyService")
@Local(PropertyService.class)
@Remote(PropertyService.class)
@PersistenceContext(name="persistence/property", unitName = "EmageonPropertyServerPU", type = PersistenceContextType.TRANSACTION)

 

try {
   javax.naming.Context cxt = (javax.naming.Context) new  InitialContext().lookup("java:comp/env");
   entityManager = (EntityManager) cxt.lookup("persistence/property");
  } catch (NamingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章