whats the difference

G

gk

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
 
P

Paul Hamaker

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

Doug Pardee

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top