This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 - Passing intialization parameters in the absence of Home interface

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jon Wetherbee
author
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic