0 Replies Latest reply on Sep 13, 2007 5:33 AM by Alexey Kostylev

    MVC application with EJB 2.1

    Alexey Kostylev Newbie


      I'm trying to build an MVC application using EJB to access a database. But I've met an unexpected problem: in my servlet (C-part of MVC) i want to use my EJB to get data through it. And that's why I must have EJB's interfaces imported into my servlet. Otherwise it won't compile. But then I'll get ClassCastException trying to do

      InitialContext init = new InitialContext();
      Object objref = init.lookup("TheNews");
      NewsHome home = (NewsHome)PortableRemoteObject.narrow(objref, NewsHome.class);

      Because interface NewsHome and objref are loaded with different ClassLoaders.

      How should I pack my ear-file and how to organize access to EJB functions: from servlet(how?) or somewhere else?