0

我最近扩展了一个 webapp,但我并没有真正扩展功能。所有页面,但一个作品。那一页应该准确地显示这一点:

http://www.bbstats.net/team-home.seam?roster=10

JSF 代码和 DAO/RosterHome 类都没有改变,只有实体类被更新以支持 LAZY 加载。但是,我不断收到以下堆栈跟踪:

javax.faces.FacesException: javax.el.ELException: /team-home.xhtml @45,49 value="#{rosterHome.label}": javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call
    at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:285)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:242)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:106)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
    at org.richfaces.renderkit.html.LayoutRenderer.renderLayout(LayoutRenderer.java:57)
    at org.richfaces.renderkit.html.LayoutRenderer.doEncodeChildren(LayoutRenderer.java:45)
    at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
    at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
    at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:265)
    at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:254)
    at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
    at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
    at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
    at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: /team-home.xhtml @45,49 value="#{rosterHome.label}": javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
    ... 52 more
Caused by: javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call
    at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1200)
    at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1150)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.seam.persistence.EntityManagerInvocationHandler.invoke(EntityManagerInvocationHandler.java:46)
    at $Proxy192.joinTransaction(Unknown Source)
    at org.jboss.seam.transaction.AbstractUserTransaction.enlist(AbstractUserTransaction.java:73)
    at org.jboss.seam.framework.EntityHome.joinTransaction(EntityHome.java:163)
    at org.jboss.seam.framework.Home.getInstance(Home.java:134)
*   at com.kawoolutions.bbstats.da.RosterHome.getLabel(RosterHome.java:22)
    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.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
    at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
    at org.jboss.seam.util.Work.workInTransaction(Work.java:61)
    at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
    at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
    at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
*   at com.kawoolutions.bbstats.da.RosterHome_$$_javassist_seam_11.getLabel(RosterHome_$$_javassist_seam_11.java)
    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 javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
    at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
    at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
    ... 53 more

在上面您可以看到涉及的 RosterHome.getLabel() 调用 (*)。这是 RosterHome 代码:

@Name("rosterHome")
public class RosterHome extends PersistenceContextEntityHome<Roster>
{
    @Override
    public String getLabel()
    {
        Roster ro = getInstance(); // line 22 is this one!!
        Team te = ro.getTeam();
        TeamType tt = te.getTeamType();
        Club cl = te.getClub();

        String teamName = cl.getName() + " " + te.getOrdinalNbr();
        String fullTeamName = teamName + " (" + cl.getShorthand() + te.getOrdinalNbr() + ")";

        String teamTypeCode = tt.getCode().toUpperCase();
        String teamTypeLabel = tt.getLabel();
        String teamType = teamTypeLabel != null ? teamTypeLabel : teamTypeCode.toUpperCase();

        return fullTeamName + ", " + teamType;
    }

    ...
}

超类 PersistenceContextEntityHome 如下所示:

public abstract class PersistenceContextEntityHome<E> extends EntityHome<E>
{   
    @Override
    protected String getPersistenceContextName()
    {
        return "em";
    }

}

那里很基本的东西,只是一个持久性上下文名称。

在 Eclipse 控制台中,我还收到以下警告:

18:05:27,693 WARN  [org.hibernate.ejb.AbstractEntityManagerImpl] (http--127.0.0.1-8080-6) HHH000326: Cannot join transaction: do not override hibernate.transaction.factory_class

然后我检查了persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
  <persistence-unit name="BBStatsPU" transaction-type="JTA">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>    
    <jta-data-source>java:jboss/datasources/BBStatsDS</jta-data-source>

    <!-- Lots of entity and ID classes .......... -->
    <class>com.kawoolutions.bbstats.model.Arena</class>
    ...

    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
      <property name="hibernate.transaction.jta.platform" value="com.kawoolutions.bbstats.util.CustomJBossAS7JtaPlatform" />
    </properties>
  </persistence-unit>
</persistence>

编辑:

com.kawoolutions.bbstats.util.CustomJBossAS7JtaPlatform.java:

public class CustomJBossAS7JtaPlatform extends JBossAppServerJtaPlatform
{
    @Override
    protected TransactionManager locateTransactionManager()
    {
        return (TransactionManager)jndiService().locate("java:jboss/TransactionManager");
    }
}

我没有在我的 web 应用程序中覆盖 hibernate.transaction.factory_class - 至少不是我所知道的。

为什么我会得到这个堆栈跟踪和上面的警告?它基本上只是一个 JSF 页面,我不断调用#{rosterHome.label}它来构建用于页面显示的自定义 HTML 标签。

我正在使用 JBoss AS 7(尝试了 7.0.0.Final 到 7.1.0.CR1 没有注意到任何差异)、Seam 2.2.2、JSF 1.2(+ Facelets)、RichFaces 3.3.3 和 Hibernate 4。

高度赞赏帮助。

谢谢

4

1 回答 1

1

答案在这里:https ://community.jboss.org/message/714893

呸。

于 2012-02-16T12:29:27.167 回答