Jsf 2 事务未在JSF@ViewScoped@Stateless bean上启动
我有一个基于JSF2Jsf 2 事务未在JSF@ViewScoped@Stateless bean上启动,jsf-2,transactions,ejb-3.0,cdi,stateless-session-bean,Jsf 2,Transactions,Ejb 3.0,Cdi,Stateless Session Bean,我有一个基于JSF2@ViewScoped的webapp,我无法正确处理事务,或者更确切地说:它们根本不启动 我也在使用JavaEE6的CDI和EJB3 这里是主要的bean: import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.inject.Inject; ... @ManagedBean @ViewScoped @Stateless public class PqMana
@ViewScoped
的webapp,我无法正确处理事务,或者更确切地说:它们根本不启动
我也在使用JavaEE6的CDI和EJB3
这里是主要的bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
...
@ManagedBean
@ViewScoped
@Stateless
public class PqManager implements Serializable
{
private List<PqListItem> pqItems;
@Inject
private PqService pqService;
public List<PqListItem> getPqItems()
{
if ( pqItems == null )
{
pqItems = pqService.findActivePqs();
}
return pqItems;
}
...
}
JpaCrudService(基本上取自Adam Bien的示例):
但是,在加载页面时,我遇到一个异常:
javax.ejb.EJBTransactionRequiredException: Transaction is required for invocation: org.jboss.invocation.InterceptorContext@7a6c1c92
at org.jboss.as.ejb3.tx.CMTTxInterceptor.mandatory(CMTTxInterceptor.java:255)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:184)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72)
at de.company.webapp.service.PqService$$$view95.findActivePqsFor(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
at de.company.webapp.service.PqService$Proxy$_$$_Weld$Proxy$.findActivePqs(PqService$Proxy$_$$_Weld$Proxy$.java)
at de.company.webapp.facade.PqManager.getPqItems(PqManager.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
.
.
.
它失败,因为调用pqService.findActivePqsFor()
未在现有事务中运行(TransactionAttributeType.MANDATORY
,它是继承的AFAIK)
请注意,通过删除JpaCrudService
上的TransactionAttributeType.MANDATORY
,并使用扩展实体管理器,可以在不使用事务的情况下正确显示页面,但这只是出于测试目的
但是为什么这不起作用呢?为什么交易不在这里开始?JSF@ViewScoped
bean中有什么东西吗?不相容
如何修复此问题?
PS:我正在使用JBossAS 7.1.1。你正在使用CDI删除JSF注释。JSF注释不能像CDI那样控制EJB。您可能将容器与正在使用的注释混淆了。您还可以将MyFaces CODI用于一些扩展,或者考虑使用CDI重新创建ViewScope。网上有几个例子 如果您正在使用CDI,请删除JSF注释。JSF注释不能像CDI那样控制EJB。您可能将容器与正在使用的注释混淆了。您还可以将MyFaces CODI用于一些扩展,或者考虑使用CDI重新创建ViewScope。网上有几个例子 谢谢。Seam 3是我正在寻找的/a解决方案吗?我终于想知道,在没有CDI的普通JavaEE6中,其他人如何从这样一个@ViewScope bean中获取事务。这将如何工作/看起来如何?是的,它会工作,但是Seam 3没有被积极开发。这项工作将进入DeltaSpike,但我们还没有讨论JSF。至于另一个问题,您需要对UserTransaction进行JNDI查找,并手动处理事务边界。我会盯着德尔塔斯派克看。谢谢你的这些顶级信息!谢谢Seam 3是我正在寻找的/a解决方案吗?我终于想知道,在没有CDI的普通JavaEE6中,其他人如何从这样一个@ViewScope bean中获取事务。这将如何工作/看起来如何?是的,它会工作,但是Seam 3没有被积极开发。这项工作将进入DeltaSpike,但我们还没有讨论JSF。至于另一个问题,您需要对UserTransaction进行JNDI查找,并手动处理事务边界。我会盯着德尔塔斯派克看。谢谢你的这些顶级信息!
//@Stateless
//@Local(CrudService.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public abstract class JpaCrudService implements CrudService
{
@PersistenceContext(unitName = "PqGeneratorPu")
protected EntityManager em;
@Override
public <T> T create(T t)
{
em.persist(t);
em.flush();
em.refresh(t);
return t;
}
...
}
<rich:dataTable value="#{pqManager.pqItems}"
var="pq">
<f:facet name="header">
<h:outputText value="Active" />
</f:facet>
...
javax.ejb.EJBTransactionRequiredException: Transaction is required for invocation: org.jboss.invocation.InterceptorContext@7a6c1c92
at org.jboss.as.ejb3.tx.CMTTxInterceptor.mandatory(CMTTxInterceptor.java:255)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:184)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72)
at de.company.webapp.service.PqService$$$view95.findActivePqsFor(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
at de.company.webapp.service.PqService$Proxy$_$$_Weld$Proxy$.findActivePqs(PqService$Proxy$_$$_Weld$Proxy$.java)
at de.company.webapp.facade.PqManager.getPqItems(PqManager.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
.
.
.