[jboss-user] [EJB 3.0] - Re: EntityManagerFactory creation failure EJB 2.1 - EJB 3.0

rkite01 do-not-reply at jboss.com
Tue May 8 13:21:37 EDT 2007


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043997#4043997

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043997



More information about the jboss-user mailing list