Example usage for org.hibernate Session reconnect

List of usage examples for org.hibernate Session reconnect

Introduction

In this page you can find the example usage for org.hibernate Session reconnect.

Prototype

void reconnect(Connection connection);

Source Link

Document

Reconnect to the given JDBC connection.

Usage

From source file:edu.ku.brc.dbsupport.HibernateUtil.java

License:Open Source License

/**
 * Reconnects a Hibernate Session to the current Thread.
 * <p>/*w  w w. j  a va2  s .c o  m*/
 * Unsupported in a CMT environment.
 *
 * @param session The Hibernate Session to be reconnected.
 */
public static void reconnect(Session session) {
    if (useThreadLocal) {
        //log.debug("Reconnecting Session to this thread.");
        session.reconnect(DBConnection.getInstance().getConnection());
        threadSession.set(session);
    } else {
        log.error("Using CMT/JTA, intercepted not supported reconnect call."); //$NON-NLS-1$
    }
}

From source file:nl.strohalm.cyclos.struts.CyclosRequestProcessor.java

License:Open Source License

private void openReadOnlyConnection(final HttpServletRequest request) {
    if (noTransaction(request)) {
        return;//from  w  w w .jav a2 s . co  m
    }
    logDebug(request, "Opening read-only transaction for include");

    final Connection connection = (Connection) TransactionSynchronizationManager
            .getResource(connectionProvider);

    final SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    final Session session = holder.getSession();
    session.setFlushMode(FlushMode.MANUAL);
    session.setDefaultReadOnly(true);
    session.reconnect(connection);

    TransactionSynchronizationManager.setCurrentTransactionReadOnly(true);
}