whats the difference

Discussion in 'Java' started by gk, Oct 25, 2006.

  1. gk

    gk Guest

    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
    gk, Oct 25, 2006
    #1
    1. Advertising

  2. gk

    Paul Hamaker Guest

    > 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
    Paul Hamaker, Oct 25, 2006
    #2
    1. Advertising

  3. gk

    Doug Pardee Guest

    EJB constructor newInstance ejbCreate

    "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.
    Doug Pardee, Oct 25, 2006
    #3
  4. gk

    gk Guest

    Re: EJB constructor newInstance ejbCreate

    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.
    gk, Oct 26, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    2
    Views:
    3,698
    Showjumper
    Jan 20, 2004
  2. =?Utf-8?B?QXNoYQ==?=

    dispose and nothing? whats the main difference?

    =?Utf-8?B?QXNoYQ==?=, Jul 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,790
    Scott Allen
    Jul 14, 2004
  3. Lucas Tam
    Replies:
    3
    Views:
    1,993
    Reza Alirezaei
    Aug 9, 2005
  4. exquisitus
    Replies:
    1
    Views:
    12,270
    Eric Sosman
    May 4, 2005
  5. Replies:
    2
    Views:
    7,882
Loading...

Share This Page