-
1. Re: Working with a stateful session bean
pimpf Mar 15, 2006 8:47 AM (in response to martinganserer)Here is one:
http://docs.jboss.org/ejb3/app-server/tutorial/injection/src/org/jboss/tutorial/injection/bean/ShoppingCartBean.java
//The example shows two ways to get access to the EJB
More examples here:
http://docs.jboss.org/ejb3/app-server/tutorial/index.html
As far as I know the only difference between stateless and statefull is that a stateful session object has a unique identity that is assigned by the container at the time the object is created.
Here is an example:
@EJB Cart cart1;
@EJB Cart cart2;
...
if (cart1.equals(cart1)) { // this test must return true
...
}
...
if (cart1.equals(cart2)) { // this test must return false
...
}
With stateless we should have:
@EJB Cart cart1;
@EJB Cart cart2;
...
if (cart1.equals(cart1)) { // this test must return true
...
}
if (cart1.equals(cart2)) { // this test must also return true, no uniqueness
...
} -
2. Re: Working with a stateful session bean
martinganserer Mar 15, 2006 9:15 AM (in response to martinganserer)Hi,
thank you for your quick response! I tried already to inject the SFSB in a SLSB but it does not work as expected.
This is a short description how it should work:
- A client creates a new stateful instance by a ctx.lookup
- The client calls a method that sets a private attribute of this SFSB.
- Afterwards a stateless session bean is called by the client.
- This bean injects the SFSB by @EJB
- If I take a look at the private attribute of the SFSB within my SLSB I will get a wrong value.
Any comments? -
3. Re: Working with a stateful session bean
pimpf Mar 15, 2006 9:38 AM (in response to martinganserer)Well,
You have two completely different instances of SFSB - one initiated by the client and one by the SLSB. @EJB has nothing to do with this... -
4. Re: Working with a stateful session bean
martinganserer Mar 15, 2006 9:44 AM (in response to martinganserer)Ok,
but how can I get the SFSB reference that the client created? Maybe it works with @Resource SessionContext ctx?
Thanks! -
5. Re: Working with a stateful session bean
bill.burke Mar 15, 2006 9:53 AM (in response to martinganserer)Don't use the @EJB annotation to inject a stateful bean into a Stateless bean. This stateful bean will never get removed.
Injecting an SFSB into another SFSB is a different story though. In this case the "nested" SFSB becomes an extension of its "parent" and is closed when the parent is closed. -
6. Re: Working with a stateful session bean
martinganserer Mar 16, 2006 2:00 AM (in response to martinganserer)Hi Bill,
do you see any chance to reference a SFSB in a stateless bean?
Regards