Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Should narrowing really be necessary in this case?  RSS feed

 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently studying Sun�s good J2EE tutorial for J2EE 1.3 but have got a problem with the example where this SalesRep-bean relates to many instances of this Customer-bean. The problem is that this line

in the method loadCustomerIds() in the SalesRep-bean cause an exception if I not change the line to

But should the narrowing really be necessary in this case? Are there any reason to why it works with the narrowing but not without it? As I have understood it should the narrowing to be used if I get an object from JNDI, particularly the home object, because you can�t be sure about in what form the object you get is (it may be Corba) but in this case when I call a remote method should it work without narrowing.

The client code that executes the two beans mentioned above is implemented in this SalesRepClient.
 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, by the way, just one more thing ... In the method loadCustomerIds() in the SalesRep-bean have a call to findBySalesRep(salesRepId) in the Customer-bean just been executed and a Collection have been returned. But look in the method ejbFindBySalesRep(String salesRepId) in the Customer-bean that implements that finder. That method calls the private method selectBySalesRep(salesRepId) which creates the Collection that is returned. That method creates a Collection of Strings, not a Collection of Customer objects. But in the method loadCustomerIds() is the objects extracted from the returned Collection Customer objects, NOT Strings. But it works (with narrowing) and I can�t see the missing step.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonny,

HFEJB describes this stuff very nice on p.120



The short answer is that as soon as your home interface is Remote than you have to use narrow. The reason is that the JNDI lookup might not return a real home stup. You might get back a IIOP stub based on your app server vendor.

Regards,
Darya
 
Jonny Andersson
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have and have read that book It was a while since I did it now and will do a thorough repetition of it as soon as I have finished Sun�s J2EE tutorial for 1.3 because one thing that were not so good with that book is that there were too few good complete exceercises and examples. But that is something the j2EE tutorial have and I really think the tutorial is a good starter before reading the book and trying to get the certification. But back to my problem ...

Yes, I know I have to narrow the returned type from the (remote) home object. But the remote method call that not works without narrowing in the example from the J2EE tutorial is not something I have got from JNDI, it is something that is returned from a business method call and as far as I remember should narrowing not be necessary in that case. Or am I wrong?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is not something I have got from JNDI

You're misunderstanding the concept of "Remote". It's not about JNDI. You may get both local objects and remote objects from JNDI. Something local is considered to be residing in the same JVM.
[ March 27, 2007: Message edited by: Satou kurinosuke ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!