I'can't access to my @EJB from my managed bean (used from a jsf page) because of this exception
javax.ejb.EJBTransactionRequiredException: Transaction is required for invocation: org.jboss.invocation.InterceptorContext@353e531e
The jsf part (pages faces-config and web.xml) is in a different package as the beans part but two are in an EAR deployed. This application is deployed on jboss 7
EJB (business):
@Stateful
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class DataAccessBusinessImpl implements DataAccessBusiness {
Managed Bean:
public class ConfigurationBean implements Serializable {
@EJB
DataAccessBusiness dab;
Faces-config.xml:
<managed-bean>
<managed-bean-name>configurationBean</managed-bean-name>
<managed-bean-class>ch.morphean.videoaid.lb.managedBean.ConfigurationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
web.xml:
<display-name>videoaid-site</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
Thank's for your help
According to the EJB specification for TransactionAttributeType.MANDATORY
:
If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context. If there is no existing transaction, an exception is thrown.
As your "client" (the managed bean) has no transaction started, the EJB container throws an exception because you have annotated your session bean with TransactionAttributeType.MANDATORY
.
Instead of using MANDATORY
as value to the @TransactionAttribute, use REQUIRED
as this will force the container to start a transaction if there isn't an existing one. The specification about TransactionAttributeType.REQUIRED
says the following:
If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.
If the client invokes the enterprise bean's method while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise bean method.