Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local / remote interfaces ?

 
Georg Joo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have two entity beans (class, student) in a unidirectional relation.
In the first bean (class) i have a add method to add a new student.

Now my questions :
1.An entity bean can have both - remote AND local interfaces, right ?
2. For the add method, I need the local interface. But I get the exception by the following statement :
student = (StudentBeanLocalHome)ctx.lookup("StudentBean");
-> a ClassCastException <-. I don't know why.

With lookup, I can get both - remote and local home, right ?
Do I have to make maybe an entry in the DD ??

thanks

Georg
 
Suman Sarker
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Georg,

I think you have to cast it right. so, instead of doing
student = (StudentBeanLocalHome)ctx.lookup("StudentBean");
do the following
student = (StudentBean)ctx.lookup("StudentBean");

Hope this helps
Suman
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suman Sarker:
Hi Georg,

I think you have to cast it right. so, instead of doing
student = (StudentBeanLocalHome)ctx.lookup("StudentBean");
do the following
student = (StudentBean)ctx.lookup("StudentBean");


Suman, I'm sure what u think is incorrect...

We cannot cast the resulting object into a bean... We need to burn the concept of "Client never talks to the client" in our brain... So you cannot cast it to the bean class...

In George case, I think he might forget to import the package, in which the Home interface is located... that's why the compiler is warning about it... If he just imports that package, I do hope everything will be ok...
 
Suman Sarker
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Georg,
Yes Ko Ko is right in saying that "Client is never allowed to directly to the Bean". So, it's not legal to Cast the resulting object into a Bean class. I am sorry and I stand corrected.

But Georg, is it the Complier that is giving you the error, or is it the Container?
 
Georg Joo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I get the exception from the container at runtime.
If I make the cast to the remote-home, it is ok (in a JSP File).

But I need the local-home (for create) to add the student to the class.

I don't know, what it could be.

Georg
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Georg Joo:

If I make the cast to the remote-home, it is ok (in a JSP File).

But I need the local-home (for create) to add the student to the class.


NO you cannot use local and remote like this... U have to develop a seperate interfaces for local home and local component objects...

Remember, local home will only create local component and remote home will only create remote component... So try to develop sthing more and you will get what you want...
 
Georg Joo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

thanks for your answer. But I have I question.

I have a bean (student). Can I have for this bean 2 home interfaces: remote-home and local-home.

Or is it not possible to have a remote-home interface, if I use the bean in a relation with class (or in an other bean) ?

Thanks for your help.

Georg
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A bean's client could have a local and a remote view. But if your bean has a local interface because your bean is in a container-managed relationship with another entity bean, then it is really hard to see why you would require a remote client interface as well.
[ May 19, 2004: Message edited by: Roger Chung-Wee ]
 
Georg Joo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Yes, it is hard (I know).

These beans are my first entity beans. I tested the student bean (without a relationship) with a JSP File (insert, update..). It was ok.

Then I set the realtion to the class bean. Now I will delete the remote-interfaces and hope the cast will go ok.

Thanks for your help

Georg
 
T Rob Darrough
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a guess ... when you deploy what class is the JNDI name "StudentBean" associated with; the local or remote component interface? I'm guessing the remote and that's why it won't cast to the local. In that case, the fix would be to put the name associated with the local component interface into your lookup call. In simpler terms, I think fix is something like ...

student = (StudentBeanLocalHome)ctx.lookup("StudentBeanLocal");
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what Georg is saying is that the deployer made StudentBean the JNDI name for the bean. This JNDI name is a logical name for the bean, it is the name that the client believes to be the name of the student bean. The JNDI name is not to be confused with the EJB name of the bean which is defined in the <ejb-name> element within the <entity> element.

A lookup on StudentBean returns a stub to the home interface. So, for a local client, the following has to be done.


Context ctx = new InitialContext();
StudentBeanLocalHome student = (StudentBeanLocalHome) ctx.lookup("StudentBean");
 
T Rob Darrough
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since he is getting ClassCastException it seems reasonable to assume lookup is finding the remote home.

I had a similiar problem to this and found that there is a window where you specify the JNDI name you are using to look other beans locally. This window exists for each bean and has a tab named something like "Referenced EJBs" (highlight the bean first). This window is different than the window where you give JNDI names that remote clients are using (highlight the jar). Further, the names you give for local clients cannot match the names given for remote clients. I am using the RI but I imagine this is all true for every compliant server.

You were saying something about the DD. I'm not sure how the DD relates to my comments. I think you must have misunderstood me.
 
Georg Joo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks to all for your help.

I found the solution. In the DD I made an entry <jndi-local-name>. With this jndi name, I get now the local home.

Georg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic