The Container throws this to a bean if the bean calls a method on its context that isn’t allowed at that time. For example, a session bean can’t ask its context for a reference to its EJB object while in the setSessionContext() method. It’s too early. A bean can also get an IllegalStateException if it calls a transaction method like setRollbackOnly() or getRollbackOnly(), when there’s no transaction!
The bean throws this to tell the Container a system exception has occurred (which forces the Container to rollback the transaction, log the exception, kill the bean, and give a local client the EJBException and a remote client a RemoteException). But the Container can also throw this for a variety of other reasons we’ll look at in a minute.
This exception is kind of a local companion to java.rmi.NoSuchObjectException. The Container throws it to the client when the client invokes a method on a local home or component interface, but there’s no underlying bean to support the object. This can happen, for example, if the bean has already been removed (either through a previous client call to remove(), or because the Container killed the bean due to an exception, stateful bean timeout, or to reduce the size of the pool).
You probably won’t see or use this exception much, especially with CMP, but it’s for you to throw from your bean code when you want to tell the Container that the entity ...