[jboss-user] [EJB 3.0] - How to initialize the State of an EJB3 Stateful Bean

Jerry Simone do-not-reply at jboss.com
Tue Mar 23 16:16:22 EDT 2010

Jerry Simone [http://community.jboss.org/people/jlsimone] replied to the discussion

"How to initialize the State of an EJB3 Stateful Bean"

To view the discussion, visit: http://community.jboss.org/message/533579#533579

Wow.  I just discovered something. Not only does Carlo's example code initialize the state of the stateful EJB, I modified it to solve another problem that I was having. Here is my modified example below.
interface MyLocal {   MyRemote create(String state);}
interface MyRemote{   void doWork(); class MyBean implement MyRemote, MyLocal {   MyRemote create(String state) {      this.state = state;      return ctx.getBusinessObject(MyRemote.class);   }      void doWork(){      // do something   }}

What I've done here is I have given the local interface the responsibility of creating the bean. This allows me to create one EJB from another EJB in the same JVM, passing the state to the second EJB by reference (instead of by value) via the local interface. This probem is described in a question I posted in another discussion thread. The link is http://community.jboss.org/thread/147136. 
The link, above, describes a problem where I am using EJBx to create EJBy within the same JVM. After I create EJBy, I  pass the remote interface for EJBy to the remote client. My problem was that I was using the remote interface (pass by value) to initailize the state of EJBy. But Carlo's modified example allows me to initialize EJBy using the local interface (pass by reference) and then have the create method return the remote interface that is needed by the remote client. 


Reply to this message by going to Community

Start a new discussion in EJB 3.0 at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100323/c287b20f/attachment.html 

More information about the jboss-user mailing list