Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EJB client cant make manny to one ClassCastException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
my first many to one test doesnt work
i get following error when i try to put something in my collection :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.ClassCastException

here is the code from my client it works until it trys to addBloks
code ----------------------------------------------

PaginaHome pagHome;
Pagina pag;
BlokTekstHome blokHome ;
BlokTekst blok;
Context ctx = new InitialContext();

Object home = (PaginaHome) ctx.lookup(PaginaHome.JNDI_NAME);
pagHome = (PaginaHome) PortableRemoteObject.narrow(home, PaginaHome.class);
pag = (Pagina)pagHome.create();


Object home1 = (BlokTekstHome) ctx.lookup(BlokTekstHome.JNDI_NAME);
blokHome = (BlokTekstHome) PortableRemoteObject.narrow(home1, BlokTekstHome.class);


Object[] bloks = new Object[2];

blok = (BlokTekst) blokHome.create();
blok.setTekst("test1");
bloks[0]=blok;

blok = (BlokTekst) blokHome.create();
blok.setTekst("test2");
bloks[1]=blok;

pag.addBlok( bloks);

code-----------------------
this is the pagina class

code----------------------------------
/*
* Created on 25-aug-2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package sven.ent.ejb;



import java.util.Arrays;
import java.util.Collection;



import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;


import sven.ent.interfaces.BlokTekstLocal;
import sven.ent.interfaces.PaginaUtil;





/**
* @author Sven
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* XDoclet-based CMP entity bean. This class must be declared
* <code>public abstract</code> because the concrete class will
* be implemented by the CMP provider's tooling.<br>
*
* To generate code:
* <br>
* <ul>
* <li> Add Standard EJB module to XDoclet project properties
* <li> Customize XDoclet configuration
* <li> Run XDoclet
* </ul>
* <br>
* Please see the included XDoclet Overview
* and the XDoclet Reference in the help system for details
*
* @ejb.bean name = "Pagina"
* type = "CMP"
* cmp-version = "2.x"
* display-name = "Pagina"
* description = "Pagina EJB"
* view-type = "both"
* jndi-name = "ejb/PaginaHome"
* local-jndi-name = "ejb/PaginaLocalHome"
*primkey-field = "id"
* @ejb.persistence table-name = "tpagina"
* @jboss.persistence table-name = "tpagina"
* @ejb:util
* generate="physical"
*/
public abstract class Pagina implements EntityBean {
/**
* @return Return the group this user is in.
* @ejb:interface-method view-type="both"
* @ejb:relation
* name="BloksRel"
* role-name="ZijnErBlokken"
* target-role-name="geefPagina"
* target-cascade-delete="yes"
*
*
*/
public abstract Collection getBloks();

/** @ejb:interface-method view-type="both"
*
*/
public abstract void setBloks(Collection bloks);


/**
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "fid"
* @ejb.pk-field
*
* @return
*/
public abstract String getId();

/**
* @ejb.interface-method view-type = "both"
*
* @param name
*/
public abstract void setId(String id);
/**
* @ejb.interface-method view-type = "both"
*
* @param Bloktekst[]
*/
public void addBlok(Object[] bloks){

setBloks(Arrays.asList((BlokTekstLocal[])bloks));
}
/**
* @ejb:interface-method view-type="both"
* @ejb ersistent-field
* @ejb.persistence column-name="ftitel"
*/
public abstract String getTitel();

/** @ejb ersistent-field
* @ejb.interface-method view-type = "both"
* */
public abstract void setTitel(String titel);


/** The EntityContext */
private EntityContext context;

/**
* @throws CreateException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*
* @ejb.create-method
*/
public String ejbCreate() throws CreateException {

this.setId(PaginaUtil.generateGUID(this));
return null;
}

/**
* @throws EJBException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*/
public void setEntityContext(EntityContext newContext) throws EJBException {
context = newContext;
}

/**
* This method is called with no transaction context.
*
* @throws EJBException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*/
public void unsetEntityContext() throws EJBException {
context = null;
}
}

manny thanks for this
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you step through this with a debugger to find out where that exception is thrown?

Maybe here ... Object home = (PaginaHome) ctx.lookup(PaginaHome.JNDI_NAME); .. or Object home1 = (BlokTekstHome) ctx.lookup(BlokTekstHome.JNDI_NAME);

??
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic