会议结束! Hibernate JTA JBoss AS 7.1.1

时间:2015-10-05 13:48:12

标签: java hibernate session jboss

这样,我们正在使用以下技术:

  • PostgreSQL 9.4
  • Java SE(jdk7u67)
  • jBPM 5.2
  • Hibernate 3.5
  • JBoss Application Server 7.1.1
  • JSF + RichFaces

应用程序在本地所有功能中都能顺利运行,但在执行负载测试时需要部署的系统,当我在执行某些任务时同时连接了3个以上的用户时,我收到以下错误:

16:12:20,742 INFO  [org.hibernate.event.def.DefaultLoadEventListener] (http--192.168.1.11-8080-6) Error performing load command: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) [hibernate3.jar:]
at org.hibernate.impl.SessionImpl.getBatcher(SessionImpl.java:288) [hibernate3.jar:]
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812) [hibernate3.jar:]
at org.hibernate.loader.Loader.doQuery(Loader.java:697) [hibernate3.jar:]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate3.jar:]
at org.hibernate.loader.Loader.loadEntityBatch(Loader.java:1980) [hibernate3.jar:]
at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:92) [hibernate3.jar:]
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062) [hibernate3.jar:]
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434) [hibernate3.jar:]
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415) [hibernate3.jar:]
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165) [hibernate3.jar:]
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223) [hibernate3.jar:]
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126) [hibernate3.jar:]
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906) [hibernate3.jar:]
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:874) [hibernate3.jar:]
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590) [hibernate3.jar:]
at org.hibernate.type.EntityType.resolve(EntityType.java:412) [hibernate3.jar:]
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139) [hibernate3.jar:]
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877) [hibernate3.jar:]
at org.hibernate.loader.Loader.doQuery(Loader.java:752) [hibernate3.jar:]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate3.jar:]
at org.hibernate.loader.Loader.doList(Loader.java:2232) [hibernate3.jar:]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) [hibernate3.jar:]
at org.hibernate.loader.Loader.list(Loader.java:2124) [hibernate3.jar:]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) [hibernate3.jar:]
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) [hibernate3.jar:]
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate3.jar:]
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) [hibernate3.jar:]
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) [hibernate3.jar:]
at com.comibol.descripcionArchivistica.dao.hibernate.DescripcionArchivoElementoEsencialDAOHibernate.obtenerListaArchivoDescritoElementoEsencial(DescripcionArchivoElementoEsencialDAOHibernate.java:28) [classes:]
at com.comibol.descripcionArchivistica.command.ObtenerListaElementoEsencialcommand.execute(ObtenerListaElementoEsencialcommand.java:31) [classes:]
at com.comibolcore.core.command.CommandHandlerBean.executeCommand(CommandHandlerBean.java:73) [classes:]
at com.comibol.descripcionArchivistica.service.DescripcionArchivisticaServiceImp.obtenerListaElementoEsencial(DescripcionArchivisticaServiceImp.java:89) [classes:]
at com.comibol.scrinia.action.descripcionArchivistica.ListadoDescripcionesArchivoAction.cargarListaElementoEsencialTemportal(ListadoDescripcionesArchivoAction.java:198) [classes:]
at com.comibol.scrinia.action.descripcionArchivistica.ListadoDescripcionesArchivoAction.ini(ListadoDescripcionesArchivoAction.java:101) [classes:]
at sun.reflect.GeneratedMethodAccessor1438.invoke(Unknown Source) [:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_80]
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstValue.getValue(AstValue.java:147) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:44) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:50) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.0.13.Final.jar:]
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIOutput.getValue(UIOutput.java:169) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80]
16:12:20,752 INFO  [stdout] (http--192.168.1.11-8080-6) MESSAGE RUNTIME org.hibernate.SessionException: Session is closed!
16:12:20,753 ERROR [com.comibol.auditoria.Log] (http--192.168.1.11-8080-6) Error al registrar log: Session is closed!|StackTrace=[Ljava.lang.StackTraceElement;@663f3166|Object=EventLog [idEventLog=143afa2307133881ccc8854c0c6e5ca413a95426, session=null, proceso=java.lang.Throwable.initCause(Throwable.java:459), descripcion=Descripcion=;
ErrorMessage=Self-causation not permitted|
Session is closed!|

我们正在使用两个数据库,一个用于应用程序,另一个用于流程引擎JBPM。

Hibernate配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/datosdb</property>
    <property name="hibernate.connection.username">datos</property>
    <property name="hibernate.connection.password">datos</property>

    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.default_schema">datos</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <!--Disable the second-level cache <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>Echo 
        all executed SQL to stdout -->

    <property name="hibernate.use_sql_comments">true</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <!--<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> -->
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
    <!--<property name="hibernate.validator.apply_to_ddl">false</property> 
        <property name="hibernate.validator.autoregister_listeners">false</property> -->
    <property name="hibernate.max_fetch_depth">5</property>
    <property name="hibernate.default_batch_fetch_size">10</property>
    <property name="connection.autocommit">true</property>

    <!--<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property> -->
    <!--<property name="jboss.as.jpa.providerModule">org.hibernate:3</property> -->

    <!-- Aqui van las property para hibernate search -->
    <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider
    </property>
    <property name="hibernate.search.default.indexBase">C:\indice\metadato</property>

    <!--Modulo Usuarios -->
    <mapping class="com.datos.usuarios.model.Usuario" /> 
    <mapping class="com.comibol.usuarios.model.Rol" /> 
    ...
</session-factory>
</hibernate-configuration>

与jbpmdb一起使用的persistence.xml文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         version="1.0"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
         xmlns="http://java.sun.com/xml/ns/persistence">

<persistence-unit name="org.jbpm.persistence.jpa"
                  transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
    <mapping-file>META-INF/JBPMorm.xml</mapping-file>

    <class>org.drools.persistence.info.SessionInfo</class>
 ...
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.connection.autocommit" value="false"/>
        <property name="hibernate.max_fetch_depth" value="3"/>
        <property name="hibernate.hbm2ddl.auto" value="none"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.transaction.manager_lookup_class"
                  value="com.datoscore.util.JBPMTransactionManager"/>
    </properties>


</persistence-unit>
<persistence-unit name="org.jbpm.task">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <mapping-file>META-INF/Taskorm.xml</mapping-file>
...
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>

        <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/jbpmdb"/>

        <property name="hibernate.connection.username" value="datos"/>
        <property name="hibernate.connection.password" value="datos"/>

        <property name="hibernate.connection.autocommit" value="false"/>
        <property name="hibernate.max_fetch_depth" value="3"/>

        <property name="hibernate.hbm2ddl.auto" value="none"/>
        <property name="hibernate.show_sql" value="false"/>
    </properties>
</persistence-unit>

使用命令模式进行交易的模式文件:

public DataAccessCommand executeCommand(DataAccessCommand c)
        throws BusinessException {
    // System.out.println("con transaccion");
    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        transaction = session.beginTransaction();
        c.setDAOFactory(daoFactory);
        try {
            c.execute();
        } catch (BusinessException e) {
            System.out.println("MESSAGE BUSINESS");
            throw new BusinessException(e.getMessage(), e,
                    e.getEnviarNotificacion());
        } catch (RuntimeException e) {
            System.out.println("MESSAGE RUNTIME " + e);
            try {
                if (transaction.isActive()) {
                    transaction.rollback();
                }
                throw new BusinessException(e, true);
            } catch (RuntimeException ex2) {
                Throwable exss = ex2;
                while (exss.getCause() != null) {
                    exss = exss.getCause();
                }
                exss.initCause(e);
                throw new BusinessException(
                        "No se pudo hacer un roll back de la transacción",
                        ex2, true);
            }
        }
        transaction.commit();
    } catch (org.hibernate.exception.ConstraintViolationException e) {
        if (transaction.isActive()) {
            transaction.rollback();
        }
        HandlerException.ProcessException(e,
                e.getStackTrace()[0].toString(), "");
        e.getSQL();
        System.out.println("e.getSQL() " + e.getSQL());
        e.getSQLException();
        System.out.println("e.getSQLException()" + e.getSQLException());
        System.out.println("e.getNextException()"
                + e.getSQLException().getNextException().getMessage());
        e.getSQLException().getNextException().getStackTrace();
        e.printStackTrace();
        throw new BusinessException(e);
    } catch (Exception ex) {
        if (transaction.isActive()) {
            transaction.rollback();
        }
        HandlerException.ProcessException(ex,
                ex.getStackTrace()[0].toString(), "");
        System.err.println("Error on executed command e :"
                + ex.getMessage());
        ex.printStackTrace();
        throw new BusinessException(ex.getMessage());
    }
    return c;
}

最后文件standalone.xml:

<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:1.2">
<extensions>
 ...
    <subsystem xmlns="urn:jboss:domain:datasources:1.0">
        <datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                <driver>h2</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <datasource jta="true" jndi-name="java:/DatosDS" pool-name="DatosPool" enabled="true" use-java-context="true" use-ccm="true">
                <connection-url>jdbc:postgresql://localhost:5432/datosdb</connection-url>
                <driver>postgresql</driver>
                <security>
                    <user-name>datos</user-name>
                    <password>datos</password>
                </security>
            </datasource>
            <datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="JbpmPool" enabled="true" use-java-context="true" use-ccm="true">
                <connection-url>jdbc:postgresql://localhost:5432/jbpmdb</connection-url>
                <driver>postgresql</driver>
                <security>
                    <user-name>datos</user-name>
                    <password>datos</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="postgresql" module="org.postgresql">
                    <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>
    <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
        <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" deployment-timeout="1200"/>
    </subsystem>
   ...
<interfaces>
    <interface name="management">
        <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
    </interface>
    <interface name="public">
        <inet-address value="${jboss.bind.address:127.0.0.1}"/>
    </interface>
    <interface name="unsecure">
        <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
    </interface>
</interfaces>

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
    <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
    <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
    <socket-binding name="ajp" port="8009"/>
    <socket-binding name="http" port="8080"/>
    <socket-binding name="https" port="8443"/>
    <socket-binding name="osgi-http" interface="management" port="8090"/>
    <socket-binding name="remoting" port="4447"/>
    <socket-binding name="txn-recovery-environment" port="4712"/>
    <socket-binding name="txn-status-manager" port="4713"/>
    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>
</socket-binding-group>
</server>

请提前帮助,谢谢。

0 个答案:

没有答案