0

我是Java新手,请帮助我理解如何正确。还有我的基础英语..

我使用 OpenShift 和之前,也许 2 周或更长时间前一切都很好,但上次我有 3 或 ~ < 20 个这样的错误:

也许 OpenShift 出了点问题?还是我做坏事?

请向我解释为什么会这样?:

Caused by: javax.resource.spi.RetryableUnavailableException: IJ000653: The pool has been shutdown (MysqlDS,178e455)

类似:IJ000453:无法获取托管连接数据源

<datasource jndi-name="java:jboss/datasources/ShopDS" enabled="${mysql.enabled}"
                use-java-context="true" pool-name="MysqlDS" use-ccm="false">
                <connection-url>jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}
                </connection-url>
                <driver>mysql</driver>
                <connection-property name="autoReconnect">true</connection-property>
                <connection-property name="useUnicode">true</connection-property>
                <connection-property name="autoCommit">false</connection-property>
                <connection-property name="characterEncoding">UTF-8</connection-property>
                <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                <pool>
                    <min-pool-size>10</min-pool-size>
                    <max-pool-size>300</max-pool-size>
                    <flush-strategy>IdleConnections</flush-strategy>
                    <prefill>true</prefill>
                </pool>
                <security>
                    <user-name>${env.OPENSHIFT_MYSQL_DB_USERNAME}</user-name>
                    <password>${env.OPENSHIFT_MYSQL_DB_PASSWORD}</password>
                </security>
                <validation>
                    <valid-connection-checker
                        class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker" />
                    <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
                    <validate-on-match>true</validate-on-match>
                    <background-validation>true</background-validation>
                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter" />
                </validation>
                <timeout>
                    <idle-timeout-minutes>60000</idle-timeout-minutes>
                </timeout>
            </datasource>

休眠.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect
        </property>
        <property name="hibernate.connection.datasource">java:jboss/datasources/ShopDS</property>
        <property name="hibernate.connection.autoReconnect">true</property>
        <property name="hibernate.connection.is-connection-validation-required">true</property>
        <property name="hibernate.connection.autocommit">false</property>
        <property name="hibernate.connection.release_mode">after_statement</property>
        <property name="hibernate.connection.useUnicode">true</property>
        <property name="hibernate.connection.characterEncoding">utf8</property>
        <property name="hibernate.connection.charSet">UTF-8</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.use_sql_comments">false</property>
        <property name="hibernate.format_sql">false</property>
        <property name="hibernate.current_session_context_class">jta</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
        <property name="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform</property>
        <property name="hibernate.transaction.auto_close_session">true</property>
        <property name="hibernate.archive.autodetection">class, hbm</property>
        <property name="hibernate.generate_statistics">true</property>
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
        <property name="hibernate.cache.use_minimal_puts">true</property>
        <property name="hibernate.cache.use_structured_entries">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.connection.pool_size">20</property>
        <property name="hibernate.default_batch_fetch_size">20</property>
        <property name="hibernate.max_fetch_depth">6</property>
        <mapping class="small.business.dao.entity.Settings" />
    </session-factory>
</hibernate-configuration>

spring-jpa-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <jee:jndi-lookup jndi-name="java:/db_EntityManagerFactory" id="entityManagerFactory"
        expected-type="javax.persistence.EntityManagerFactory" cache="true" />

    <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <!-- Process the PersistenceUnit and PersistenceContext annotations -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    </bean>

    <!-- <bean class="org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor"> -->
    <!-- <property name="sessionFactory" ref="sessionFactory" /> -->
    <!-- </bean> -->

    <bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />
    <tx:annotation-driven />
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:/TransactionManager" />
        <property name="userTransactionName" value="java:jboss/UserTransaction" />
        <property name="transactionSynchronizationRegistryName" value="java:jboss/TransactionSynchronizationRegistry" />
    </bean>
</beans>

使用 @Transactional 注释调用的 GenericDAO 方法

package small.business.dao;

import java.lang.reflect.ParameterizedType;

import javax.persistence.EntityManager;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.exception.GenericJDBCException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import small.business.domainmodel.interfaces.IElement;

/**
 * 
 * @author 452
 */
public abstract class GenericDAO<E extends IElement<?>> {

    private static final Logger log = LoggerFactory.getLogger(GenericDAO.class);

    protected Class<E> entityClass;

    @Autowired
    protected EntityManager entityManager;

    @Autowired
    protected SessionFactory sessionFactory;

    @SuppressWarnings("unchecked")
    public GenericDAO() {
        entityClass = (Class<E>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    @SuppressWarnings("unchecked")
    public E getCurrentElement(Long currentElement) {
        E element = null;
        try {
            //element = entityManager.find(entityClass, currentElement);
            Session session = sessionFactory.getCurrentSession();
            //element = (E) session.load(entityClass, currentElement);
            element = (E) session.get(entityClass, currentElement);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
        }
        return element;
    }

    public E saveOrUpdate(E currentElement) throws Exception {
        E result;
        try {
            result = entityManager.merge(currentElement);
        } catch (GenericJDBCException e) {
            try {
                result = entityManager.merge(currentElement);
            } catch (GenericJDBCException ex) {
                throw new Exception("saveOrUpdate: ", ex);
            }
        }
        return result;
    }

    public void remove(E currentElement) throws Exception {
        E element = entityManager.find(entityClass, currentElement.getId());
        entityManager.remove(element);
    }
}

堆栈跟踪:

at java.lang.Thread.run(Thread.java:722) 
        Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/ShopDS 
            at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137) 
            at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141) 
            at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:276) 
            at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297) 
            ... 161 more 
        Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/ShopDS 
            at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:390) 
            at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:368) 
            at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464) 
            at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129) 
            ... 164 more 
        Caused by: javax.resource.spi.RetryableUnavailableException: IJ000653: The pool has been shutdown (MysqlDS,178e455) 
            at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:264) 
            at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getTransactionNewConnection(AbstractPool.java:495) 
            at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:374) 
            at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:329)

JBoss AS 7.1.1、MySql 5、Hibernate 4、Spring 3.2.2

4

1 回答 1

0

还尝试通过 ssh 连接到您的应用程序(rhc ssh {appName}),并查看是否可以通过在控制台上运行“mysql”来连接到数据库。如有必要,请尝试使用“rhc Cartridge restart mysql-5.1 {appName}”重新启动 mysql 盒。+1 检查您的 mysql 日志是否有错误:
https ://openshift.redhat.com/community/faq/how-to-troubleshoot-application-issues-using-logs

于 2013-05-23T20:51:34.790 回答