This content has been marked as final.
Show 1 reply
-
1. Re: EntityManagerFactory creation failure EJB 2.1 - EJB 3.0
rkite01 May 8, 2007 1:21 PM (in response to rkite01)I ended up using the InitialContext to lookup the EntityManagerFactory. Not sure if this is the correct way or not but it works. Below is the new code.
// Example of getting EJB 3.0 beans from EJB 2.1 Session Bean.
public List findPosts(String userLogin) throws Exception
{
InitialContext initialContext = new InitialContext();
Object obj = initialContext.lookup("java:/imEjb30Factory");
EntityManagerFactory entityManagerFactory = (EntityManagerFactory)obj;
EntityManager entityManager = entityManagerFactory.createEntityManager();
Query query = entityManager.createNamedQuery("findPosts");
query.setParameter(1, userLogin);
List list = query.setMaxResults(10).setFirstResult(0).getResultList();
return(list);
}