Discussion:
Constructors In Ejb
(too old to reply)
pradeep tiwari
2005-01-13 14:56:12 UTC
Permalink
Hi All,
Can I use constructors in EJB(session,entity).If yes ,is there any restrictions.
Thanks In Advance
bill kemp
2005-01-13 15:28:46 UTC
Permalink
You can use constructors in your EJB's. The problem that you face is that
the environment and context that the bean will execute in is not defined.
So, you are not able to access the EJBContext, the EJBObject, resource
managers, client info, transaction info, or the local JNDI namespace.
Because of this, you generally don't want to do anything in a constructor.
It is usually better to put initialization code in the ejbCreate method(s),
or the ejbPostCreate method(s). The spec has a couple of tables that show
what operations are allowed in the various methods of the different flavor
beans and they all show that there is no access to anything in the EJB
environment in the constructor.

Bill
Post by pradeep tiwari
Hi All,
Can I use constructors in EJB(session,entity).If yes ,is there any restrictions.
Thanks In Advance
Amit Mujawar
2005-02-08 04:43:22 UTC
Permalink
Here is what I think about your question..
What will you achieve by using a constructor of an EJB?
Sure, you can say new beanName(); and get an object of an entity bean. But where is the container involved??? it will be just a plain java object in such a case and no "life cycle" method / operations would be done on it.
As such you are in no way allowed to control the life cycle of an entity bean ..it has to be managed by Container. What you can do is - you call methods on it remote interface. Here is the catch - you can NOT access the constructor of the bean implementation class through its remote interface. So there is absolutely no question of you invoking a constructor and the created object acting as an entity bean. Also I would like to differ from the previous answer which says , you can call a constructor but the context is not defined. I go ahead to say that there is no "context" involved as such since the constructor will just create a plain java object.
Loading...