• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Remote / Local beans problem (WSAD 5)

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,
Now I have javaBean, remote session bean and local entity bean.
I use them like that :
Jsp --> JavaBean --> SessionBean --> EntityBean.

I�ve added local references for entity to ejb-jar. (Did not add any reference for session since it is remote and did not add any ref to web.xml since I do not call entity from servlet). So I did everything according your previous instructions. And�
I can do lookup of SessionBean in javaBean code. But cannot do lookup of EntityBean in SessionBean code. It gives me the same error in console log:
javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".
May be the reason is that both session and entity should either remote or local and cannot one be remote and the other one be local?
Or something wrong with ref settings?
Thanks in advance
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably something wrong with the ref setting. Post the few lines of code around the lookup and ONLY the section of your ejb-jar.xml file that defines the session bean and I'll look at it.
Kyle
 
Jenny Kalinina
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is for remote session bean:
< session id="TimeReportAction">
< ejb-name>TimeReportAction</ejb-name>
< home>echargeit.session.TimeReportActionHome</home>
< remote>echargeit.session.TimeReportAction</remote>
< ejb-class>echargeit.session.TimeReportActionBean</ejb-class>
< session-type>Stateless</session-type>
< transaction-type>Container</transaction-type>
</session>
This is code in session bean to lookup entity bean:
public class TimeReportActionBean implements javax.ejb.SessionBean {
public echargeit.entity.Timedetail_masterLocalHome home;
public echargeit.entity.Timedetail_masterLocal tdmlocal;

private echargeit.entity.Timedetail_masterLocalHome lookupTdm()
throws NamingException
{
System.out.println("home before lookup");
InitialContext ctx = new InitialContext();
return (echargeit.entity.Timedetail_masterLocalHome)ctx.lookup
("java:comp/env/ejb/echargeit/entity/Timedetail_masterLocalHome");
}
public ArrayList getTimeReportsOnDate(BigDecimal staffno, Timestamp dateentered, String wipid)
{

try
{
System.out.println("home before lookup");
home = lookupTdm();
System.out.println("after homelookup ");
}
catch(NamingException e)
{
e.printStackTrace();
System.out.println("naming exc of lookup: " + e);
}
This is ref for entity bean:
< ejb-local-ref id="EJBLocalRef_1043274577185">
< description></description>
< ejb-ref-name>ejb/echargeit/entity/Timedetail_masterLocalHome</ejb-ref-name>
< ejb-ref-type>Entity</ejb-ref-type>
< local-home>echargeit.entity.Timedetail_masterLocalHome</local-home>
< local>echargeit.entity.Timedetail_masterLocal</local>
< ejb-link>Timedetail_master</ejb-link>
</ejb-local-ref>
Thank you
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may seem like a silly question, but is the ejb-reference defined IN the session EJB defined above? e.g. is the < ejb-local-ref> section between the < session> and < /session> tags of that bean?
Kyle
 
Jenny Kalinina
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.
It is REMOTE session bean,
so why it should be there?
Thanks
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jenny, the way that EJB references work is that you declare them on the bean in which you use them. A reference is a "namespace" that is unique to that bean. You declare references to other beans within the context of the bean you are writing.
I REALLY suggest that you go read Richard Monson-Haefel's EJB book -- he goes over this in detail with several good examples...
Also, the sidebar on this article might help you understand how local references work, also.
Kyle
[ January 24, 2003: Message edited by: Kyle Brown ]
 
Jenny Kalinina
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kyle,
But I've done exactly that way you describe it. I declare and do lookup of session bean (which is remote) in javaBean where I called that session bean.
Then I declare and do lookup of entity bean in session bean where I called that entity.(That is code I posted)
I just do not understand how should I add local ref to ejb-jar, because I cannot add local ref to remote session bean. It doesn't allow to do that. It says
"selected bean doesn't contain a local client view"
I have local ref on entity bean but cannot lookup it anyway.
I'll definately will read that book and article as soon as I can. But sofar I even do not have a second - need to do urgent project
Thanks again
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we have a basic misunderstanding about what the local references mean. A local reference is just a "pointer" off to something else. You don't declare the local reference in the bean that you are referencing, you declare them in the bean that REFERENCES that bean.
So, what I am saying is that the < session> declaration for your TimeReportAction bean must contain an < ejb-local-ref> to your Timedetail_masterLocalHome local Entity bean. That is why I asked my question.
Kyle
 
Jenny Kalinina
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,
Thank you very much for beeing so patience.
With your help my beans work well now
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are very welcome, Jenny. I'm glad everything is working now.
Kyle
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic