EJB: Problem with concurrent calls to EJBs (according to JBoss)
I'm working on a EJB project on JBoss.
I have a connection to DB for every user. I can't use the JNDI pool of connections, because every user connects with his/her own password. So I created a stateful session bean that "remembers" the username and password and the DB connection.
That has worked perfectly.
Of course, due to the fact that I'm working with my own DB connections, I'm using BMP. What I do to "share" une user's connection with all the beans (in one user's session) is have the connection be one of the elements of the PK instance. When I have to work with the DB in the entity beans, I get the connection from the PK. That's a solution that has worked perfectly so far.
However I just learned on friday that Session Beans don't support concurrent calls. That approach doesn't work because I was sharing a single Connection Session bean among all the entity beans, therefore it was possible that two beans wanted to ask the connecion bean for a DB operation. I just started to get problems when I inserted code for ejbLoad() in one of my beans. As the server calls ejbStore anytime, It's obvious the call was happening when There was another Connection Session bean operation going on.
I decided to give each bean one clone of the Connection Session bean. Now each bean has its very own Connection Bean to ask for DB operations at any time. (Remember, the DB connection is handled by a Connection Session bean).
But this approach fails too. :'( I don't know why.
I have decided to change my approach radically and include the DB username and password in the PK instance so that I will create a brand new Connection bean every time one entity bean is to be active.
Do you have other ideas?
|