Example usage for org.hibernate.engine.internal StatefulPersistenceContext getEntitiesByKey

List of usage examples for org.hibernate.engine.internal StatefulPersistenceContext getEntitiesByKey

Introduction

In this page you can find the example usage for org.hibernate.engine.internal StatefulPersistenceContext getEntitiesByKey.

Prototype

@Deprecated
@Override
public Map getEntitiesByKey() 

Source Link

Usage

From source file:to.etc.domui.hibernate.generic.HibernateLongSessionContext.java

License:Open Source License

@Override
public void conversationDestroyed(AbstractConversationContext cc) throws Exception {
    if (m_session == null || !m_session.isConnected())
        return;/*from   w w w  . j a v a 2  s.com*/
    try {
        setConversationInvalid("Conversation was destroyed");
        setIgnoreClose(false);
        SessionImpl sim = (SessionImpl) m_session;
        StatefulPersistenceContext spc = (StatefulPersistenceContext) sim.getPersistenceContext();
        Map<?, ?> flups = spc.getEntitiesByKey();
        if (LOG.isDebugEnabled())
            LOG.debug("Hibernate: closing (destroying) session " + System.identityHashCode(m_session)
                    + " containing " + flups.size() + " persisted instances");
        if (m_session.getTransaction().isActive())
            m_session.getTransaction().rollback();
        close();
    } catch (Exception x) {
        LOG.info("Exception during conversation destroy: " + x, x);
    }
}

From source file:to.etc.domui.hibernate.generic.HibernateLongSessionContext.java

License:Open Source License

@Override
public void conversationDetached(AbstractConversationContext cc) throws Exception {
    if (m_session == null || !m_session.isConnected())
        return;//w  w w. ja v  a 2 s  . c  o m
    setConversationInvalid("Conversation is detached");
    SessionImpl sim = (SessionImpl) m_session;
    StatefulPersistenceContext spc = (StatefulPersistenceContext) sim.getPersistenceContext();
    Map<?, ?> flups = spc.getEntitiesByKey();
    if (LOG.isDebugEnabled())
        LOG.debug("Hibernate: disconnecting session " + System.identityHashCode(m_session) + " containing "
                + flups.size() + " persisted instances");

    /*
     * 20180829 jal Hibernate 5.2 clears its session cache during rollback, so that all
     * entities disappear. There is no real way in its code to prevent that. As an experiment
     * do not manipulate Hibernate's transaction here; just disconnect the connection.
     */
    //if(m_session.getTransaction().isActive())
    //   m_session.getTransaction().rollback();
    m_session.disconnect(); // Disconnect the dude.
    //      if(m_session.isConnected())
    //         System.out.println("Session connected after disconnect ;-)");
}

From source file:to.etc.domui.hibernate.generic.HibernateReattachingDataContext.java

License:Open Source License

@Override
public void conversationDetached(AbstractConversationContext cc) throws Exception {
    if (m_session == null)
        return;//from  w  ww . j  a  v  a2s . co m

    /*
     * jal 20080822 Attempt to fix org.hibernate.NonUniqueObjectException by saving all objects currently in the session and
     * reattaching them automagically at conversation attach time.
     */
    long ts = System.nanoTime();
    SessionImpl sim = (SessionImpl) m_session;
    StatefulPersistenceContext spc = (StatefulPersistenceContext) sim.getPersistenceContext();
    Map<?, ?> flups = spc.getEntitiesByKey();
    m_hibernatePersistedObjects.clear();
    for (Object ent : flups.values()) {
        //         System.out.println(">> Got entity: "+ent);
        m_hibernatePersistedObjects.add(ent);
    }
    ts = System.nanoTime() - ts;
    if (LOG.isDebugEnabled())
        LOG.debug("hib: saved " + flups.size() + " persisted objects in the conversation for reattachment in "
                + StringTool.strNanoTime(ts));
    close();
}