[jboss-user] [Beginners Corner] - classCastException when doing JNDI lookup

Quake4Ialdaris1 do-not-reply at jboss.com
Fri Aug 3 01:28:44 EDT 2007


Hey guys,

so I'm trying to do a JNDI lookup on a simple EJB.  I'm following these instructions: http://www.netbeans.org/kb/50/jboss-getting-started.html

Inside my listNews servlet I do the following:

    private NewsEntityFacadeLocal lookupNewsEntityFacade()
    {
        try
        {
            Context c = new InitialContext();
            return (NewsEntityFacadeLocal) c.lookup("NewsApp/NewsEntityFacade/local");
        }
        catch(NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
            throw new RuntimeException(ne);
        }
    }
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try
        {
            Context c = new InitialContext();
            //NewsEntityFacade ref = (NewsEntityFacade)c.lookup("NewsApp/NewsEntityFacade/local");
            NewsEntityFacade ref = (NewsEntityFacade)lookupNewsEntityFacade();
            out.print("<h1>WE'RE GOOD!!!!!</h1>");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

Here is my NewsEntityFacade:

@Stateless
public class NewsEntityFacade implements NewsEntityFacadeLocal {

    @PersistenceContext
    private EntityManager em;
    
    /** Creates a new instance of NewsEntityFacade */
    public NewsEntityFacade() {
    }

    public void create(NewsEntity newsEntity) {
        em.persist(newsEntity);
    }

    public void edit(NewsEntity newsEntity) {
        em.merge(newsEntity);
    }

    public void destroy(NewsEntity newsEntity) {
        em.merge(newsEntity);
        em.remove(newsEntity);
    }

    public NewsEntity find(Object pk) {
        return (NewsEntity) em.find(NewsEntity.class, pk);
    }

    public List findAll() {
        return em.createQuery("select object(o) from NewsEntity as o").getResultList();
    }
}

and here is my NewsEntityFacadeLocal interface:

@Local
public interface NewsEntityFacadeLocal {
    void create(NewsEntity newsEntity);

    void edit(NewsEntity newsEntity);

    void destroy(NewsEntity newsEntity);

    NewsEntity find(Object pk);

    List findAll();
}


When I run the code I get:

01:25:31,074 ERROR [STDERR] java.lang.ClassCastException: $Proxy110
01:25:31,074 ERROR [STDERR] 	at web.ListNews.processRequest(ListNews.java:49)
01:25:31,074 ERROR [STDERR] 	at web.ListNews.doGet(ListNews.java:81)
01:25:31,074 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
01:25:31,074 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
01:25:31,074 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
01:25:31,075 ERROR [STDERR] 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
01:25:31,075 ERROR [STDERR] 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
01:25:31,075 ERROR [STDERR] 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
01:25:31,075 ERROR [STDERR] 	at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
01:25:31,075 ERROR [STDERR] 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
01:25:31,076 ERROR [STDERR] 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
01:25:31,076 ERROR [STDERR] 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
01:25:31,076 ERROR [STDERR] 	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
01:25:31,076 ERROR [STDERR] 	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
01:25:31,076 ERROR [STDERR] 	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
01:25:31,076 ERROR [STDERR] 	at java.lang.Thread.run(Thread.java:613)


Any clues?

thanks

alessandro ferrucci

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

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



More information about the jboss-user mailing list