| Author |
EJB3 - Passing intialization parameters in the absence of Home interface
|
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8147
|
|
|
In EJB2.x for a session bean there used to be a home interface which had a create(...) method through which parameters could be passed which would then be used during the initialization of the beans. Now that EJB3 no longer needs the home interfaces, how is this passing of initialization parameters handled?
|
[My Blog] [JavaRanch Journal]
|
 |
Jon Wetherbee
author
Ranch Hand
Joined: Oct 05, 2006
Posts: 33
|
|
Hi Jaikiran- A Home (and/or LocalHome) interface is still required if you need to initialize the stateful session bean with argument data upon creation. It is optional if you don't need to initialize the bean, or if it is okay to follow up the instantiation with an explicit initialization method call, through the business interface (beware of this route, if it is essential that this method be called before any other business method on the session bean). To use a Home or LocalHome interface, you can either continue to use the EJB 2.x style ejbCreate(a, b) method, if this was an EJB 2.x bean, or you can define your own initialization method with params that match your [Local]Home.create(a, b) method, and annotate it @Init (or define it using an init-method entry in ejb-jar.xml). Regards, Jon
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8147
|
|
Jon, thanks for replying.
A Home (and/or LocalHome) interface is still required if you need to initialize the stateful session bean with argument data upon creation
To use a Home or LocalHome interface, you can either continue to use the EJB 2.x style ejbCreate(a, b) method, if this was an EJB 2.x bean
Which would mean i will have to extend my home/localhome interface from the EJBHome and EJBLocalHome interfaces, right? And also the session bean implementation should implement SessionBean?
or you can define your own initialization method with params that match your [Local]Home.create(a, b) method, and annotate it @Init (or define it using an init-method entry in ejb-jar.xml).
You mean, something like: If so, when injection is used(or even if the bean is accessed through JNDI lookup), how would the *container*(which is going to invoke this method) be able to pass some application specific parameters to this myInit method? Am i right, or did i get something wrong here?
|
 |
 |
|
|
subject: EJB3 - Passing intialization parameters in the absence of Home interface
|
|
|