Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

whats the difference

Thread view: 
gk - 25 Oct 2006 10:57 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.