| Author |
ClassCastException returned from PortableRemoteObject.narrow
|
chuck keuper
Greenhorn
Joined: Mar 17, 2004
Posts: 22
|
|
I have a client /* * Created on Oct 12, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package com.synesis7.mcsi3.admin.versioncontrol.submitepdr.entity.client; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import com.synesis7.mcsi3.admin.versioncontrol.submitepdr.entity.interfaces.*; import java.util.*; public class EntityClient { public static void main(String[] args) { try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory"); env.put(Context.PROVIDER_URL,"iiop://127.0.0.1:3700"); //get naming context Context context = new InitialContext(env); //look up jndi name Object ref = context.lookup(ChangeDocsEntityHome.JNDI_NAME); //JNDI_NAME remote //Object ref = context.lookup("ejb/ChangeDocsEntityHome"); //JNDI_NAME remote //look up jndi name and cast to Home interface ChangeDocsEntityHome home = (ChangeDocsEntityHome)PortableRemoteObject.narrow(ref,ChangeDocsEntityHome.class); //ChangeDocsEntityLocalHome home = (ChangeDocsEntityLocalHome)PortableRemoteObject.narrow(ref,ChangeDocsEntityLocalHome.class); Integer value = new Integer("1"); ChangeDocsEntity hl = home.findByPrimaryKey(value); //ChangeDocsEntityLocal hl = home.findByPrimaryKey(value); System.out.println("notes = " + hl.getNotes()); System.out.println("reason change = " + hl.getReasonChg()); System.out.println("recommendataion = " + hl.getRecommendation()); } catch (Exception e) { e.printStackTrace(); System.out.println("Exception e = " + e.getMessage()); } } } When I run in debug i get java.lang.ClassCastException at the narrow statement. The Exception e = null. I am running with SunApServ 8 with Eclipse 3.0.1. Any help would greatly be appreciated.
|
 |
Ali balawala
Greenhorn
Joined: Oct 19, 2004
Posts: 4
|
|
Why dont you do a System.out.println on "ref" and see if the JNDI lookup is actually returning an object. If it does retun an object, the output might give you an idea of what it has returned
|
 |
 |
|
|
subject: ClassCastException returned from PortableRemoteObject.narrow
|
|
|