Can anybody explain me role of default parameterless constructor in EJB bean classes(session+entity).
is it compulsory to provide these constructors?
according to 2.0 spec (7.10.2) -
The session bean class must have one default pareterless constructor.
but, I have created a entity bean component( infact, using the JBuilder generated beans) which is not having any constructor, and still working fine.
Please help me clear this constructor concept for both entity and session bean.
That statement doesn't actually set a requirement for the application server... It just says that the application server <i>may</i> expect the existence of the constructor. It doesn't <i>have to</i> throw an exception if the constructor is missing.
According to the Java standard, all classes will have at least one constructor. If you do not specify a constructor, the default contructor will be created when compiling. The default constructor is public and as no arguments.
All EJB:s must have this constructor, and personally I recommend to leave the code without any constructor and let the compiler do the job.
If you are curious you must have a default no args constructor on an EJB becuase the actual object is created using Class.newInstance() which calls this constuctor.
Tomas is correct. As long as we're talking about the Java standard, the default constructor will not be generated unless the superclass has an empty constructor (the compiler wouldn't know which superclass constructor to call).
Thanks to All.