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?
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.
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?
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
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"
He got surgery to replace his foot with a pig. He said it was because of this tiny ad: