• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remote and Local Interface for the Same Bean Class?

 
Ali Ragi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering if it is possible that the same bean class, let's say session bean, can have both remote and local Component and home interfaces so that the bean can be used and accessible by the remote client as well as by the other bean locally?
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, although there are some caveats. The non-business methods are relatively easy - creates and removes generally take no extra work, ditto for finders on CMT entity beans. Its really the business methods you have to keep an eye on.
- Local interfaces pass by value, so for the same methods to behave correctly with remote clients, your beans can't depend on their client sharing state with them (this is a bad idea even with local clients)
- You have to restrict yourself to legal RMI-IIOP types for return values and method args if you want to expose a business method in both interfaces
- Methods in a remote interface can't expose local interface objects (you can't return the EJBLocalObject, for example). If you need to return some kind of ejb object, you'll need probably need two methods - one for remote clients and another for local clients.
 
Ali Ragi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
So in the jar file for that kind of bean, there will be both remote and local interfaces - 2 files and (local) home interfaces another 2 files and 1 bean class file will total 5 files for that bean? How about the deployement - DD for that kind of bean? Is it diff or the same with regular bean?
 
Sunil Patil
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali,

So in the jar file for that kind of bean, there will be both remote and local interfaces - 2 files and (local) home interfaces another 2 files and 1 bean class file will total 5 files for that bean? How about the deployement - DD for that kind of bean? Is it diff or the same with regular bean?

In deployment descriptor you will have to declare both local-home,home,remote and local interface.
But in case if you want to use local inteface of the EJB you have to add ejb-ref in user bean with interface type as local and get reference to this bean from beans context (i.e.java:comp/env/aliasname)
Sunil
 
Ali Ragi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sunil!
So If a bean can real have five files - 4 interfaces files and 1 bean class file, I break the Ed Roman's rule for "The Triad of Beans" in his "Mastering Enterprise JavaBeans". Now it's "The Five of Beans"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic