[jboss-user] [JBoss Seam] - No concurrent calls on stateful bean!
toni
do-not-reply at jboss.com
Wed Jan 3 06:16:50 EST 2007
Hi,
if I send many simultaneous HTTP requests to my seam application, which carry out a particular action, then I get an exception.
To reproduce this I have create a short test application, which you find below.
The test application exists of a JSF Table, which displays a set of entities. Each entity bean can be deleted by clicking on a "delete" link.
If I delete the entity beans sequentially, then everything works correctly. However, if I very quickly click on many links, then sometimes I get the following exception:
Caused by: javax.ejb.ConcurrentAccessException: no concurrent calls on stateful bean 'jboss.j2ee:service=EJB3,name=TemplateAction' (EJB3 4.3.13) at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:73)
I read of course, that this happens for reentrant calls on beans (A->B->A) or when one starts a thread inside a EJB, but that's not what I'm doing.
I already upgraded to SEAM 1.1, because I thought might/could be a bug. But I guess it's my lack of understanding.
To reproduce the error, I have create the following example, so that people here can reproduce the error. Just copy and paste the source code it into an existing project and call "/test.seam".
It takes only 3-4 minutes. I appreciate any comments and help.
Toni
Test.java
-------------
@Entity
@Name("test")
public class Test
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id;
String testText;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getTestText()
{
return testText;
}
public void setTestText(String testText)
{
this.testText = testText;
}
}
BasicTest.java
---------------------
@Local
public interface BasicTest
{
public String list();
public String create();
public String select();
public String save();
public String delete();
public void destroy();
public DataModel getDataModel();
}
TestAction.java
------------------------
@Name("testAction")
@Stateful
public class TestAction implements BasicTest
{
@In(create = true)
EntityManager entityManager;
@In(create = true)
@Out
@Valid
Test test;
@Out(required = false)
DataModel dataModel;
@Begin(join = true)
public DataModel getDataModel()
{
if (dataModel == null)
dataModel = new ListDataModel();
dataModel.setWrappedData(entityManager.createQuery("from Test").getResultList());
return dataModel;
}
@Begin(join = true)
public String list()
{
return "tests";
}
public String create()
{
test = new Test();
return "test";
}
public String select()
{
test = (Test) dataModel.getRowData();
return "test";
}
@End
public String save()
{
entityManager.merge(test);
return "tests";
}
@End
public String delete()
{
entityManager.remove(dataModel.getRowData());
return "tests";
}
@Destroy
@Remove
public void destroy()
{
}
}
----------- test.jsp --------------
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>
<f:view>
<h:form>
<s:validateAll>
<h:panelGrid columns="1">
<h:outputText value="Type"/>
<h:inputText size="20" value="#{test.testText}"/>
</h:panelGrid>
<h:messages/>
<h:commandButton type="submit" value="Save" action="#{testAction.save}"/>
</s:validateAll>
</h:form>
</f:view>
----------- tests.jsp ----------------------
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>
<f:view>
<h:form>
<h:outputText value="No Test Entities available" rendered="#{testAction.dataModel.rowCount == 0}"/>
<h:dataTable value="#{testAction.dataModel}" var="t" rendered="#{testAction.dataModel.rowCount > 0}">
<h:column>
<f:facet name="header">
<h:outputText value="Type"/>
</f:facet>
<h:outputText value="#{t.testText}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Action"/>
</f:facet>
<h:commandLink value="delete" action="#{testAction.delete}"/>
</h:column>
</h:dataTable>
</h:form>
<h:outputLink value="test.seam">
<f:param name="conversationId" value="#{conversation.id}"/>
<h:outputText value="Create Another Test Entity"/>
</h:outputLink>
</f:view>
-------------- add to faces config ---------------------
<navigation-rule>
<navigation-case>
<from-outcome>tests</from-outcome>
<to-view-id>/tests.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>test</from-outcome>
<to-view-id>/test.jsp</to-view-id>
</navigation-case>
</navigation-rule>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3997490#3997490
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3997490
More information about the jboss-user
mailing list