Bean Creation: when an object becomes a bean

setSessionContext() and ejbCreate() happen only once in a session bean’s life, so don’t blow it! And don’t try to do things too soon... the constructor is too early to do any bean things.

A bean moves from does not exist to method ready (still feels creepy... doesn’t it have to exist before it can move?), beginning with a constructor. But the constructor makes an object, not a bean. To be a bean, the object needs to be granted beanness.
When an object becomes a bean, it gets all the unique privileges that come with beanness, like the ability to get security info about the client, or look up special deploy-time properties in the bean’s special space in JNDI, or get a JDBC Connection from a pool managed by the container.
Why do you care about creation details?
Because somewhere between the constructor and the create() method, the bean is in a Schroedinger’s bean[8] state. You might have bean initialization code, like getting a JDBC Connection, or looking up a reference to another bean, that will fail if you run it too early in the bean’s life. Writing good bean code means you must know the point at which an object becomes a card-carrying bean and what that means to you as the developer.
What does “beanness” buy you?
What happens when a bean goes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access