the following methods are called in creating a seesion bean instance
newInstance(), setSessionContext(), ejbCreate()
i dont understand the difference between newInstance() and ejbCreate()
it seems both of them are same.
are not they creating instances ?
newInstance() --->container creates new instance ......new instance of
what ? new EJB instance ?
ejbCreate() ---->ah...it creates EJB instance ...i think
please somebody let me know the difference between these two.
thank you
Paul Hamaker - 25 Oct 2006 14:33 GMT
> newInstance() --->container creates new instance ......new instance of
> what ? new EJB instance ?
Yes.
> ejbCreate() ---->ah...it creates EJB instance ...i think
No, it is called to initialize the instance, somewhat like a
constructor.
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com
Doug Pardee - 25 Oct 2006 17:50 GMT
"newInstance" isn't a method in your EJB. It's
java.lang.Class.newInstance().
The EJB container (server) can't just do a "new" on your class because
there's no way to hard-code your classname into the Java sources for
the EJB server. So it does a Class.forName on the classname that it
gets from the deployment descriptor; this gives it the Class object for
your EJB class. Then it does a newInstance on that Class object to get
an instance of your EJB class.
At that point the JVM will call your EJB's constructor. After that the
EJB server will call setSessionContext and then ejbCreate (for session
beans). In most cases, all of your initialization code can be in
ejbCreate.
Things are different for entity beans, where ejbCreate is only called
when a new entity (database row or whatever) is being created.
gk - 26 Oct 2006 10:49 GMT
thank you
nice answer.
> "newInstance" isn't a method in your EJB. It's
> java.lang.Class.newInstance().
[quoted text clipped - 13 lines]
> Things are different for entity beans, where ejbCreate is only called
> when a new entity (database row or whatever) is being created.