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();
}