Constructors in Session Beans

Hi all!

I'm trying to understand the basic concepts of EJB. Starting with Session Beans I read that all these beans must implement a default constructor, for instance:

publicclass HelloBeanimplements SessionBean

....

public HelloBean(){}

....

And I read that also other parametric constructors can be implemented in this bean cass if the sb is stateful.

Now: I cannot understand why I must implement a constructor when it is never used. I know that the instance is created only after a call of the method create of the ejb home object by the client..May someone expain this issue to me?

Thanks!!

[837 byte] By [albertthea] at [2007-11-27 9:20:53]
# 1

Hi albert,

In EJB, the developer does not use constructors at all for bean classes.The bean must have

a no-arg constructor so that the container is able to new() the class, but the constructor should

not contain any code.It's typically better to just not implement the no-arg constructor and let

the javac compiler automatically generate it according to the standard language rules.

The way the developer writes instance initialization code in EJB 2.1 (and earlier) is through the

use of a special create method.The home or local home interface declares the create method

and its implemented on the bean class using the name ejbCreate.A stateful session bean

ejbCreate method can have parameters.A stateless session bean ejbCreate method always

takes 0 parameters.

--ken

ksaksa at 2007-7-12 22:14:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
evrything is clear now, thanks!
albertthea at 2007-7-12 22:14:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...