Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to initialize a no-interface Stateful bean through annotation?

 
Rob Micah
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a method defined in my Stateful bean I want to be an "initializer" can I use that somehow when creating a reference to it in a client through the @EJB annotation?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you want to do :-)

Do you want just to have an initializer method for your SFSB? If so, can you use the @PostConstruct annotation on your method?

Cheers!
 
Rob Micah
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have a method in the bean like

So that when the bean is instantiated it's provided a String to work with. And restrict it to only being initialized that way. I just don't know how to make that work with something like this:
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where from would you like this String argument come? From the client?
 
Rob Micah
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it will come from the client.
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know you can only initialize an EJB using @PostConstruct method which takes no parameters. It's invoked by the container and it's the only hook to use between class instantiatation and giving it's EJB nature.

I think you'll need to go with specific business method that you'll invoke in order to store the data as a part of the conversational state. If the particular data / parameter is required to be set for further processing, you can check this and throw i.e. some IllegalStateException or ApplicationException.
 
Rob Micah
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought there was a way to do this, without using annotation/dependency injection, by creating an ejbCreate() method in the local interface that had parameters and then when looking up through JNDI you pass those parameters to the create() method. Am I mistaken?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then sorry, I'm not aware of how the EJB 2.x were used... I worked only with 3.x.
 
Anastasia Klimchuk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, there are several annotations that deal with Stateful beans initialization,

But this seems like returning to old style. As I understand, these annotations were mainly added to provide backward compartibility with EJB 2.1.

and... wow the same advice is here http://www.coderanch.com/t/318886/EJB-JEE/java/EJB-Passing-intialization-parameters-absence
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic