首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hibernate配置3.3.2.GA托管会话

hibernate配置3.3.2.GA托管会话
EN

Stack Overflow用户
提问于 2015-07-15 21:53:39
回答 1查看 131关注 0票数 0

什么是正确的设置来确保会话hibernate.cfg.xml 50个用户?在Hibernate 3.3.2.GA版本中,因为当超过5个用户连接时,我的应用程序不会响应对数据库的某些请求。

好的,这是配置文件

代码语言:javascript
复制
<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/scriniadb</property>
    <property name="hibernate.connection.username">scrinia</property>
    <property name="hibernate.connection.password">scrinia</property>

    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.default_schema">scrinia</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>

    <!--Mapping class -->

我以这种方式对逻辑和控制会话使用命令模式

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2015-07-15 22:39:50

正如@M.Deim所说,你的naver关闭了seesion对象。transaction.commit();只会将更改提交到DB并刷新当前会话。

围棋练习如下:

代码语言:javascript
复制
try
{
   Session session = HibernateHrlper.getSession();
   Transaction transaction = session.beginTransaction();

   // Do your Work here

   session.save(object);
   transaction.commit();
}
catch(Exception e)
{
   if(transaction !=null)
   {
      transaction.rollback();
   }
}
finally
{
   if(session !=null && session.isOpen())
   {
        session.close();
        session = null;
   }
   if(transaction !=null)
   {
        transaction = null;
   }
} 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31432387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档