COnstructors in EJB


EJB programming & troubleshooting: COnstructors in EJB

  1. COnstructors in EJB (5 messages)

    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.


    Threaded Messages (5)

  2. COnstructors in EJB[ Go to top ]

    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.
  3. COnstructors in EJB[ Go to top ]


    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.

  4. COnstructors in EJB[ Go to top ]

    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.

  5. COnstructors in EJB[ Go to top ]

    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).

  6. COnstructors in EJB[ Go to top ]

    Thanks to All.