aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Can we access the Bean with local interface inside client in same package as bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Can we access the Bean with local interface inside client in same package as bean?" Watch "Can we access the Bean with local interface inside client in same package as bean?" New topic
Author

Can we access the Bean with local interface inside client in same package as bean?

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,

I have heard that we can only access bean locally through other beans inside same container & we can not access bean trough local interface from normal java client though client will be in same package as that of bean.
Is this true???

Thanx in advance.

Prash


********Deserve Before You Desire********
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
No it is not true. The local interface can be used by clients running in the same EJB container and same Java virtual machine. Clients not only include EJBs but also other co located Java classes.


http://www.skillassert.com


Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10213
    
166

normal java client

If this is a standalone java client you *will have to* use remote interfaces, since this standalone class will be using its own JVM. You *cant* use local interfaces in this case
[ February 15, 2006: Message edited by: jaikiran pai ]

[My Blog] [JavaRanch Journal]
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
Dear Prashant,

My reply is based on the assumption that normal java client though client will be in same package as that of bean refers to a Java class containing the code to create instance of Context (or InitialContext) and doing a lookup with the Local EJB JNDI name.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
A local client must be in the same application as the EJB it is calling. This means that the client must be packaged in the same EAR file or exploded directory as the EJB.

If the client and EJB are in different applications, let us say different EAR files, then the client must be remote even if both apps are deployed to the same server instance.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,
This is my directory structure for EJB:-
========
CartMasterBean.java -- Bean Implementation class
CartMaster.java -- Bean Remote class
CartMasterLocal.java -- Bean Local Remote class
CartMasterLocalHome.java -- Bean Home class
CartMasterHome.java -- Bean Remote Home class
Client.java --------Simple Java Program (Client) Accessing Bean through Local Home Interface as follow
"CartMasterLocalHome cm=(CartMasterLocalHome)initialcontext.lookup("CartMasterLocal")"
========

Here "CartMasterLocal" is the local JNDI name for EJB.

Now can I access the Bean in this client?

Pls tell me.
Thanx.
Prash
Andreas Schaefer
Ranch Hand

Joined: Feb 13, 2006
Posts: 63
I think you mix things up here. As someone already pointed out a local interface can only accessed by a class within the same application (JAR or EAR). A local interface does not have the means to be invoked remotely but also class loading issues prevent you from accessing the local interface from another application (JAR/EAR) because these two applications are loaded by different class loaders. This means that even when your client in another application does have the local interface the class obtained from the JNDI service is different from the one locally and you will end up in a Class Cast Exception.
Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
HI Andreas ,

Thanx for ur reply. I got my mistake.
I would like to have ur mail ID in my mail list. If u dont mind then give me ur id.
My id is tiwari_p_k@yahoo.com
Thanx.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we access the Bean with local interface inside client in same package as bean?