-
1. Change Datasource by HttpSession
mp911de May 21, 2011 6:49 AM (in response to jean.baldessar)Hi Jean,
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.
Best regards,
Mark
-
2. Re: Change Datasource by HttpSession
jean.baldessar May 23, 2011 3:21 PM (in response to mp911de)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?
Any suggestion?
-
3. Change Datasource by HttpSession
wdfink May 23, 2011 1:39 PM (in response to jean.baldessar)1 of 1 people found this helpfulI'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.
-
4. Change Datasource by HttpSession
mp911de May 23, 2011 2:30 PM (in response to jean.baldessar)Hi Jean,
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.
Best regards,
Mark
-
5. Re: Change Datasource by HttpSession
jean.baldessar May 23, 2011 3:34 PM (in response to mp911de)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!
-
6. Re: Change Datasource by HttpSession
jean.baldessar May 23, 2011 4:35 PM (in response to jean.baldessar)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?
-
7. Re: Change Datasource by HttpSession
mp911de May 23, 2011 11:35 PM (in response to jean.baldessar)JBoss cares for you :-)
-
8. Re: Change Datasource by HttpSession
jean.baldessar May 24, 2011 2:39 PM (in response to mp911de)Good... Thanks Mark!