在项目中和数据库中表映射的 *.hbm.xml 
<hibernate-mapping>
    <class lazy="false"> 在<class>元素中添加lazy="false" 
</class>
<hibernate-mapping>

解决方案 »

  1.   

    先贴段hibernate源码 明天继续研究public Object execute(HibernateCallback action, boolean exposeNativeSession) throws DataAccessException {    
            Assert.notNull(action, "Callback object must not be null");    
       
            Session session = getSession();    
            boolean existingTransaction = SessionFactoryUtils.isSessionTransactional(session, getSessionFactory());    
            if (existingTransaction) {    
                logger.debug("Found thread-bound Session for HibernateTemplate");    
            }    
       
            FlushMode previousFlushMode = null;    
            try {    
                previousFlushMode = applyFlushMode(session, existingTransaction);    
                enableFilters(session);    
                Session sessionToExpose = (exposeNativeSession ? session : createSessionProxy(session));    
                Object result = action.doInHibernate(sessionToExpose);          flushIfNecessary(session, existingTransaction);    
                return result;    
            }    
            catch (HibernateException ex) {    
                throw convertHibernateAccessException(ex);    
            }    
            catch (SQLException ex) {    
                throw convertJdbcAccessException(ex);    
            }    
            catch (RuntimeException ex) {    
                // Callback code threw application exception...    
                throw ex;    
            }    
            finally {    
                if (existingTransaction) { //你错误出现信息地方                logger.debug("Not closing pre-bound Hibernate Session after HibernateTemplate");    
                    disableFilters(session);    
                    if (previousFlushMode != null) {    
                        session.setFlushMode(previousFlushMode);    
                    }    
                }    
                else {    
                    // Never use deferred close for an explicitly new Session.    
                    if (isAlwaysUseNewSession()) {    
                        SessionFactoryUtils.closeSession(session);    
                    }    
                    else {    
                        SessionFactoryUtils.closeSessionOrRegisterDeferredClose(session, getSessionFactory());    
                    }    
                }    
            }    
        }