I'm trying to have a generic method for doing the same. All my entity
beans extend DomainEntityBean, use the same primary key class DomainPK, and
their remote interface extend DomainEJBObject.
So in DomainEntityBean, i have :

 public static DomainEJBObject findByOid(Class homeInterfaceClass, int oid) throws 
RemoteException{
    DomainPK primaryKey=new DomainPK(oid);
    try {
      InitialContext initialContext=new InitialContext();
      EJBHome 
home=(homeInterfaceClass)PortableRemoteObject.narrow(initialContext.lookup(homeInterfaceClass.toString()),homeInterfaceClass);
      return home.findByPrimaryKey(primaryKey);
    } catch (NamingException e) {
      throw new EJBException("Impossible d'obtenir l'interface locale AuteurHome");
    } catch (FinderException e) {
      throw new EJBException("Impossible de trouver un auteur avec l'oid "+oid);
    }
  }
But i got a compilation error : homeInterfaceClass is not a Class
So, is there a way to have a dynamic cast ?

Also, is there a problem using the same primary key class for every beans ?

Guillaume

Le ven, 07 avr 2000, vous avez �crit :
> For EJBs that need to be looked up a lot within the server code, I code in 
> a static lookup() function in the implementation class. E.g. in 
> ContributionLogEntryBean:
> 
> /**Static convenience method for looking up ContributionLogEntry objects.*/
> public static ContributionLogEntry lookup(int iKey) throws RemoteException
> {
>       try
>       {
>       Context ctx = new InitialContext();
>       String sHomeName = 
> EJBHelpers.getHomeInterfaceClassName(ContributionLogEntryHome.class);
>               ContributionLogEntryHome home = 
> (ContributionLogEntryHome)ctx.lookup(sHomeName);
>       return home.findByPrimaryKey(new ContributionLogEntryPK(iKey));
>       }
>       catch (FinderException e) {throw new RemoteException(null,e);}
>       catch (NamingException e) {throw new RemoteException(null,e);}
> }
> 
> Then when the implementation of another bean needs to grab a 
> ContributionLogEntry it can just do ContributionLogEntryBean.lookup(). Note 
> that the use of a static helper here is perfectly valid - it's just 
> equivalent to inserting this code in the calling function.
> 
> Joe
> 
> 
> -----Original Message-----
> From: Joel Shellman [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, April 04, 2000 9:50 PM
> To:   [EMAIL PROTECTED]
> Subject:      Entity bean to Entity bean call
> 
> In the ejbCreate method of my entity bean (MemberBean) it needs to:
> 1) lookup another entity bean (another MemberBean) via a finder method
> (findByLogin)
> 2) just the primary key back (can I do that? I don't need the whole
> object)
> 
> Is there a standard way of doing that or do I need to call out to
> getting initialcontext, lookup, etc.?
> 
> Thank you,
> 
> Joel Shellman
> http://www.ants.com/
> ----
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body of the message "unsubscribe jonas-users".
> For general help, send email to [EMAIL PROTECTED] and
> include in the body of the message "help".
> 
> ----
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body of the message "unsubscribe jonas-users".
> For general help, send email to [EMAIL PROTECTED] and
> include in the body of the message "help".
-- 
Guillaume Rousse

Iremia - Universit� de la R�union
15 avenue Ren� Cassin, BP 7151
97715 Saint Denis, messagerie cedex 9
Tel:0262938330 Fax:0262938260 ICQ:10756815

And now, some words for our sponsor :
Explosives, guns, assassination, conspiracy, primers, detonators, Kakadan,
initiators, main charge, nuclear charges, ambush, sniping, motorcade, IRS,
ETA, FARC, Cuba, Castro, Che Guevara, revolution, ATTAC, BATF, jtf-6...
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to