if you have only a few Data Sources you could lookup your Persistence Context manually, skipping Dependency Injection (@PersistenceContext).
Dependency Injection isn't built for too much dynamic.
Hi Mark, thanks for replying.
I think it will work for me. But there's one more thing to think about, maybe you can help me.
There is a lot of stateless session beans accessing the database by dependency injection.
The state of my application is kept in the HttpSession, so I think lookup the persistence context dynamically would envolve to pass some parameter that identifies the context I want to use and then do the lookup based on it. It requires a lot of refactoring in my stateless session beans methods to adding this parameter.
Is it better to do this with some statefull session bean keeping the state of the selected persistence context for each logged user?
I was thinking in implement a session listener that update this statefull session bean. It's a good idea?
I dont have any patice with statefull session beans... how could I do it?
1 of 1 people found this helpful
I've done SFSB in a webapp to store login and shopping carts for a session, but you have to cleanup the SFSB or adjust the timeout that it will be removed and the connection is going back to pool.
Otherwise you get in trouble with it.
try to keep your Session-Data Front-Most. HttpSession is a good place for this (e. g. it's very easy to setup Http-Clustering and sharing this way the Session-Data across your servers). It's also the most common way. Sometime it sucks to pass always and always your Session-Stuff...
As Wolf-Dieter said, when you go Stateful you need to maintain more things than you do now.
Ok, I think the main question is already responded.
Now i just need to think in a good way to modify my application without a big impact
thanks Mark and Wolf-Dieter!
Mark, forgot to ask something important
If I get my persistence context by dynamic lookup, will I have to begin and commit transactions and close my EntityManager? Or JBoss still doing it to me even without dependency injection?
JBoss cares for you :-)
Good... Thanks Mark!