I have an EJB Stateless Session Bean. I have these requirements:
- This Stateless EJB should be initialized at startup
- The initialization code should make a transactional access to a database
The problem is:
- @Startup is only available for @Singleton EJBs
- @PostConstruct annotation (at least on Websphere) doesn't have a transactional context at this point so the initialization code explode here!
Possible solutions?
- Use a Java EE Timer but it seems to be designed for periodic execution. I want just only one execution at time zero.
- Use a @Singleton + @Startup EJB just for initialization purposes and inject this singleton EJB to the dependant Stateless EJBs.
Question:
- Can any one explain how it is supposed a Stateless EJB to be initialized? or it has no sense? (I mean, stateless EJB are supposed to not to have initialization state?)
- Is there any pattern out there that says use of secondary EJB @Singleton with @Startup is a good idea?
@Singletons
but after re-reading it I can see you are using 2) to refer to your original Stateless case. – Dashing