Discussions

EJB programming & troubleshooting: EJB Local Bean Call from Web Container

  1. EJB Local Bean Call from Web Container (3 messages)

    Hi All, My application has web module and ejb module bundled in a single ear. It will be deployed using this ear. In my appl, can i make a local bean call from web module to ejb module? ie. i have session bean as local interface in ejb module. Can i call this bean from any utility class in web module. If not, then why? If yes, please provide me a sample code for local bean initial context look up. Thanks in Advance, Gokul
  2. Re: EJB Local Bean Call from Web Container[ Go to top ]

    Yes, you may use local interfaces when acting within the same JVM. Search the net for examples, any basic tutorial will show you the way. Regards Niklas
  3. A quick reply to your question is "Yes" But why do you want to use a local interface for the bean ?? -You will not be able to scale your application. -And you seem to be calling regular session beans from the war. Use local interface with entity beans only .. this is done primarily to make sure that the DB and beans synergize and work on the same JVM efficiently. However, with hibernate you could just have Web Session Beans Entity 2.1 or Hibernate. hope i helped. -Vinant Pandey
    Hi All,

    My application has web module and ejb module bundled in a single ear. It will be deployed using this ear.

    In my appl, can i make a local bean call from web module to ejb module?
    ie. i have session bean as local interface in ejb module. Can i call this bean from any utility class in web module.

    If not, then why?

    If yes, please provide me a sample code for local bean initial context look up.



    Thanks in Advance,
    Gokul
  4. This is however not entirelly true... There is one and only one true reason of using local interfaces: the objects don't get serialized / deserialized whenever passing an object reference to a methid in a remote interface. All other reasons are really subeffects of this. Serializing / deserializing objects has a great performance cost when doing it many times, especially if it might as well been in vain, in the case of acting within the same JVM. Regarding scaling using local interfaces: there is no reason whatsoever that you can't scale your application using local interfaces. In some cases, you might want to apply remote interfaces to your facade beans, but if you are certain that your web container will be located within the same JVM as your EJB container, go for local interfaces. Develop your interfaces using a business interface, that you let both your local and remote interfaces inherit from. That way, you may transparently switch from local to remote interfaces if the need comes up, without having to rewrite any code. The reason about DB optimization, etc, is just not true. And the DB is absoultely not running in your JVM! The only optimization taking place is the one not needing serializaiton/deserializatin. The DB has no whatsoever clue about that your application even uses EJB, and even less does it care about which interfaces your application uses (and it really shouldn't care!). So, shortly, the only difference between local and remote interfaces is the serializing of objects, and each serialization that takes place within the same JVM is a waste of cpu cycles! Use local interfaces everywhere to avoid performance penalties, until you are forced to do otherwise. In these rare cases, there will be no impact in your code if you have been coded against a business interface rather than the local interface directly. Regards Niklas