Session bean create() vs. entity bean create()

  1. Stateful session bean create()

    • Client calls it to get an EJB object reference to a new just-for-me stateful session bean.

    • It can (and frequently does) have arguments, that the bean uses to do client-specific initialization (before running any business methods).

    • The Container makes a new session bean when the client calls create()

  2. Stateless session bean create()

    • Client calls it to get an EJB object reference to a bean

    • It has no arguments, and the bean does not do any client-specific initialization (since at the time the bean’s ejbCreate() is called, the bean has no association with a client!)

    • The Container does not make a new session bean when the client calls create(), and does not pull one out of the pool until the client invokes a business method.

  3. Entity bean create()

    • Client calls it to insert a new row in the database!* Although the end result for the client is still an EJB object reference (in this case, to the newly-created entity).

    • It will virtually always have arguments (although they aren’t mandatory, but it’s kinda hard to imagine a create() without them... like, “Hey database, create a new customer... no, I don’t have any name or ID or anything... just make some stuff up”).

    • The Container does not make a new entity bean, but it does pull one out of the pool to run the ejbCreate() method. Remember, the ejbCreate() method has to take the create() arguments and somehow create a new entity in the underlying persistent store (or at least support ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.