-
1. Re: Stateless Session Bean in Application context
matt.drees May 3, 2008 7:56 AM (in response to mbelicek)You can't have a Stateless session bean in the Application context (or any stateful context). IIRC, if you annotate a component both @Stateless and @Scope(ScopeType.APPLICATION), Seam will throw an exception.
-
2. Re: Stateless Session Bean in Application context
matt.drees May 3, 2008 8:02 AM (in response to mbelicek)If you want an EJB that lives in the application context, it'll have to be a stateful session bean. You could either use @Startup and @Create, as mentioned, or use an @Observer("org.jboss.seam.postInitialize") method. I tend to prefer the latter.
-
3. Re: Stateless Session Bean in Application context
mbelicek May 5, 2008 10:04 AM (in response to mbelicek)With stateful session bean I would get the concurent access performance problem. So I guess using a pojo in application context is the answer. Thanks for the hint with the Observer.
-
4. Re: Stateless Session Bean in Application context
mbelicek May 5, 2008 10:25 AM (in response to mbelicek)Seam will not throw any exception (2.0.1.GA). That's the reason why I'm asking. I have seen some examples on the net with this combination but they might be wrong. I don't know. So I guess it would be nice if somebody could bring some light on the matter.
-
5. Re: Stateless Session Bean in Application context
matt.drees May 6, 2008 4:56 AM (in response to mbelicek)Just looked through the code, and it doesn't look like it throws an exception like I thought it did, as you say.
It looks like what will happen is it will store the reference in the specified scope. So, if you had a @Stateless component with @Scope(APPLICATION), you'd keep the same reference. Of course, this doesn't help for @Stateless beans; I imagine if you tried to store information in it you'd see sometimes get that data back, but sometimes not (because of pooling, as you mentioned).
I'm not sure why Gavin didn't throw an exception in this scenario. Maybe this was an oversight? Maybe it's intentional, because this could allow you to avoid a jndi lookup every time you need to get a reference to your stateless component. I don't know enough about EJB to know if that's useful or not.
Anyone else have thoughts?
In my opinion, Seam should throw an exception.
-
6. Re: Stateless Session Bean in Application context
jazir1979 May 6, 2008 5:06 AM (in response to mbelicek)In my app I use a stateless session bean in stateless scope, but with a number of @Factory methods whose results get stored in the Application context.
I use this for returning lists of entities for select boxes, etc. And it seems to work very well.
eg:
@Factory(value = "allRoles", scope = ScopeType.APPLICATION) public List<Role> getAllRoles() { return roleService.getAllRoles(); }