Hi there,
I am not sure how to solve your problem with sharing SessionContext
(my guess: entity listeners, as far as I can tell, share session
context with beans that triggered them), but what wonders me the most
is what actually are you using stateful beans for?
What String parameters are you willing to keep between invoking your
stateful session beans? My advice is: never use stateful session beans
if you really do not have to. Stateless session beans are much less
problematic in general.
Regards,
Witold Szczerba
2008/3/31, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> Hello,
>
> I have the following question:
> I have a web application that is accessed from several fat J2SE clients. All logging happens on the server, i.e. the clients access a stateful session bean that acts as a facade for server-side log4j. The clients submit an ID, making it possible to identify a specific client in the logs. This works fine so far:
>
> On the server:
> [code]
> public interface Logger {
> public void log(String msg);
> }
>
> @Stateful
> public class LoggerBean implements Logger {
> public void log(String msg) { ... }
> }
> [/code]
>
> And on the client:
>
> [code]
> Logger logger = (Logger) new InitialContext().lookup(Logger.class.getName());
> logger.log("something");
> [/code]
>
> There is another stateful session bean that acts as a facade between the clients and JPA:
>
> [code]
> @Stateful
> public class PersistenceFacade {
> public Object findEntity(Class c, Object primaryKey) { return entityManager.findEntity(c, primaryKey); }
> }
> [/code]
>
> And on the client:
>
> [code]
> Example example = (Example) new InitialContext().lookup(Example.class.getName());
> example.setValue(foobar);
> ...
> [/code]
>
> Now my problem is that when a client tries to access an entity bean, and someting happens in the entity bean, it can't log to the client's logger bean instance as it has no way of knowing about this instance. Entity beans are instantiated from the EntityManager and I can't pass the instance of the logger bean to them:
>
> [code]
> @Entity
> public class Example {
> public void setValue(Object o) {
> try { foobar(o); }
> catch(Exception e) {
> logger.log(e.toString()); // how to get the current session's logger bean instance?
> }
> }
> [/code]
>
> Is there any way, maybe some kind of SessionContext, into which I could put the logger bean instance in the session bean and from which I can retrieve it in the entity bean?
>
> Thanks in advance for all your useful answers.
>
> Greetings
>
> ronin
> [Message sent by forum member 'ronin2' (ronin2)]
>
> http://forums.java.net/jive/thread.jspa?messageID=266803
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>