Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > whats the difference

Reply
Thread Tools

whats the difference

 
 
gk
Guest
Posts: n/a
 
      10-25-2006
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

 
Reply With Quote
 
 
 
 
Paul Hamaker
Guest
Posts: n/a
 
      10-25-2006
> 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

 
Reply With Quote
 
 
 
 
Doug Pardee
Guest
Posts: n/a
 
      10-25-2006
"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.

 
Reply With Quote
 
gk
Guest
Posts: n/a
 
      10-26-2006
thank you
nice answer.

Doug Pardee wrote:
> "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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
whats the difference between xp pro sp1 and sp2 ??? sonic MCSE 3 12-08-2010 07:55 PM
Web Services vs. Remoting Hosted In IIS - Pros/Cons Whats the difference? Lucas Tam ASP .Net 3 08-09-2005 06:07 PM
Whats the difference between Hash and Map ? exquisitus Java 1 05-04-2005 03:29 PM
dispose and nothing? whats the main difference? =?Utf-8?B?QXNoYQ==?= ASP .Net 3 07-14-2004 02:40 PM
Whats the difference between IDataAdapter and IDbDataAdapter? Showjumper ASP .Net 2 01-20-2004 02:09 PM



Advertisments