Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCastException returned from PortableRemoteObject.narrow  RSS feed

chuck keuper
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

//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) {
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!