Hot questions for Using Enterprise JavaBeans in javabeans


I have a couple of EJBs that are called from a jax-rs web service. However, every time I call one of the EJB methods I am intercepting the invocation using an interceptor. This interceptor checks the parameters for an API key and if it is not present or doesnt exist in my database it will throw an exception that I wish to catch in my jax-rs code. However, since my jax-rs class has no knowledge of the possibility of this exception being thrown even though the exception could be a checked exception, what would be the best practice here?

  1. Declaring my EJB to throw exceptions (without ever throwing them itself)
  2. Making my exception an unchecked exception and checking for it anyways?
  3. Something else?


I figured out that throwing an unchecked exception would be the best. I then use an exception mapper to catch the exception and handle it.

The only thing that's left is to suppress the exception output to the log files.



The plain term "bean" is frequently used as as a shortcut to JavaBean or Enterprise Java Bean (depending on the context). So, the term exists in the common language of programmers and it refers in general to reusable objects/components in Java.

JavaBean is a POJO class with specific naming conventions for getters and setters, true and not only that: it is usually an encapsulation of other objects (properties), is serialisable and with a zero-argument constructor. There is a complete specification developed by Sun (at that moment) about JavaBean. Sun defined it as "a reusable software component that can be manipulated visually in a builder tool". Moreover, in JavaBean Specification it is stated that:

Individual Java Beans will vary in the functionality they support, but the typical unifying features that distinguish a Java Bean are:

  • Support for "introspection" so that a builder tool can analyze how a bean works
  • Support for "customization" so that when using an application builder a user can customize the appearance and behaviour of a bean
  • Support for "events" as a simple communication metaphor than can be used to connect up beans
  • Support for "properties", both for customization and for programmatic use.
  • Support for persistence,so that a bean can be customized in an application builder and then have its customized state saved away and reloaded later.

The essential part is that can be visually manipulates hence the need for getters/setters, events, zero-argument constructor (so that they can be externally instantiated), serialisable.

Check this link for more details:


i'm new to Ejb developing so this might be a newbie question. I'm developing an application with the common service facade pattern; in this way, my local and remote interface can't know my session bean parameters, so i can only pass simple data between facade and presentation layer. Which is the best solution to made possible to pass the same content of my bean between facade and presentation layer? Should i duplicate in some way my bean to made it visibile outside to presentation layer?



Your SessionBean should not be transferred between service layer and presentation layer. Typically your presentation layer should have a reference of your remote or local service interface(s) which is initialized using the @EJB CDI framework.

Behind the scene:

The CDI framework then inject an instance of your service interface implementation. If you are using the service remotely, it uses RMI technology to get that instance and transfer the stub using JRMP protocol.

I think you don't want to transfer these SessionBeans between those layers. You need to pass complex DTOs (data transfer objects) as argument to the SessionBean's methods. Is my understanding right?

If so you may want to create some POJO (plain old java objects which contains some properties or fields and some setter getter methods + at least a default no-arg constructor) which implements interface.

In this case you can use this java objects as the arguments of the SessionBean's method.

Hope this would be helpful,

Good Luck.