java类org.hibernate.FlushMode的实例源码

SpringSessionSynchronization.java 文件源码 项目:lemon 阅读 28 收藏 0 点赞 0 评论 0
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();

        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.MANUAL.
        if (!FlushMode.isManualFlushMode(session.getFlushMode())) {
            try {
                logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            } catch (HibernateException ex) {
                throw SessionFactoryUtils
                        .convertHibernateAccessException(ex);
            }
        }
    }
}
HibernateJpaDialect.java 文件源码 项目:lams 阅读 32 收藏 0 点赞 0 评论 0
@Override
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name)
        throws PersistenceException {

    Session session = getSession(entityManager);
    FlushMode flushMode = session.getFlushMode();
    FlushMode previousFlushMode = null;
    if (readOnly) {
        // We should suppress flushing for a read-only transaction.
        session.setFlushMode(FlushMode.MANUAL);
        previousFlushMode = flushMode;
    }
    else {
        // We need AUTO or COMMIT for a non-read-only transaction.
        if (flushMode.lessThan(FlushMode.COMMIT)) {
            session.setFlushMode(FlushMode.AUTO);
            previousFlushMode = flushMode;
        }
    }
    return new SessionTransactionData(session, previousFlushMode);
}
SpringSessionSynchronization.java 文件源码 项目:lams 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();
        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.MANUAL.
        if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
            try {
                SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            }
            catch (HibernateException ex) {
                throw SessionFactoryUtils.convertHibernateAccessException(ex);
            }
        }
    }
}
SpringSessionSynchronization.java 文件源码 项目:lams 阅读 32 收藏 0 点赞 0 评论 0
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();
        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.NEVER/MANUAL.
        if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
            try {
                SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            }
            catch (HibernateException ex) {
                throw translateException(ex);
            }
        }
    }
}
HibernateTransactionManager.java 文件源码 项目:lams 阅读 34 收藏 0 点赞 0 评论 0
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
    if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
        HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
        Session session = txObject.getSessionHolder().getSession();
        if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
            logger.debug("Performing an early flush for Hibernate transaction");
            try {
                session.flush();
            }
            catch (HibernateException ex) {
                throw convertHibernateAccessException(ex);
            }
            finally {
                session.setFlushMode(FlushMode.MANUAL);
            }
        }
    }
}
QueryBinder.java 文件源码 项目:lams 阅读 38 收藏 0 点赞 0 评论 0
private static FlushMode getFlushMode(FlushModeType flushModeType) {
    FlushMode flushMode;
    switch ( flushModeType ) {
        case ALWAYS:
            flushMode = FlushMode.ALWAYS;
            break;
        case AUTO:
            flushMode = FlushMode.AUTO;
            break;
        case COMMIT:
            flushMode = FlushMode.COMMIT;
            break;
        case NEVER:
            flushMode = FlushMode.MANUAL;
            break;
        case MANUAL:
            flushMode = FlushMode.MANUAL;
            break;
        case PERSISTENCE_CONTEXT:
            flushMode = null;
            break;
        default:
            throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
    }
    return flushMode;
}
QueryBinder.java 文件源码 项目:lams 阅读 27 收藏 0 点赞 0 评论 0
private static FlushMode getFlushMode(AnnotationInstance[] hints, String element, String query) {
    String val = getString( hints, element );
    if ( val == null ) {
        return null;
    }
    if ( val.equalsIgnoreCase( FlushMode.ALWAYS.toString() ) ) {
        return FlushMode.ALWAYS;
    }
    else if ( val.equalsIgnoreCase( FlushMode.AUTO.toString() ) ) {
        return FlushMode.AUTO;
    }
    else if ( val.equalsIgnoreCase( FlushMode.COMMIT.toString() ) ) {
        return FlushMode.COMMIT;
    }
    else if ( val.equalsIgnoreCase( FlushMode.NEVER.toString() ) ) {
        return FlushMode.MANUAL;
    }
    else if ( val.equalsIgnoreCase( FlushMode.MANUAL.toString() ) ) {
        return FlushMode.MANUAL;
    }
    else {
        throw new AnnotationException( "Unknown FlushMode in hint: " + query + ":" + element );
    }
}
NamedQueryLoader.java 文件源码 项目:lams 阅读 26 收藏 0 点赞 0 评论 0
@Override
public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
    LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName );

    // IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then
    // do an internal lookup of the entity from the PC.

    final AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery( queryName );
    if ( query.hasNamedParameters() ) {
        query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() );
    }
    else {
        query.setParameter( 0, id, persister.getIdentifierType() );
    }

    query.setOptionalId( id );
    query.setOptionalEntityName( persister.getEntityName() );
    query.setOptionalObject( optionalObject );
    query.setFlushMode( FlushMode.MANUAL );
    query.list();

    // now look up the object we are really interested in!
    // (this lets us correctly handle proxies and multi-row or multi-column queries)
    return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) );

}
NamedQueryCollectionInitializer.java 文件源码 项目:lams 阅读 36 收藏 0 点赞 0 评论 0
public void initialize(Serializable key, SessionImplementor session)
throws HibernateException {

       LOG.debugf("Initializing collection: %s using named query: %s", persister.getRole(), queryName);

    //TODO: is there a more elegant way than downcasting?
    AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery(queryName);
    if ( query.getNamedParameters().length>0 ) {
        query.setParameter(
                query.getNamedParameters()[0],
                key,
                persister.getKeyType()
            );
    }
    else {
        query.setParameter( 0, key, persister.getKeyType() );
    }
    query.setCollectionKey( key )
            .setFlushMode( FlushMode.MANUAL )
            .list();

}
Department.java 文件源码 项目:unitimes 阅读 39 收藏 0 点赞 0 评论 0
public Department findSameDepartmentInSession(Long newSessionId, org.hibernate.Session hibSession){
    if (newSessionId == null){
        return(null);
    }
    Department newDept = Department.findByDeptCode(this.getDeptCode(), newSessionId, hibSession);
    if (newDept == null && this.getExternalUniqueId() != null){
        // if a department wasn't found and an external uniqueid exists for this 
        //   department check to see if the new term has a department that matches 
        //   the external unique id
        List l = hibSession.
        createCriteria(Department.class).
        add(Restrictions.eq("externalUniqueId",this.getExternalUniqueId())).
        add(Restrictions.eq("session.uniqueId", newSessionId)).
        setFlushMode(FlushMode.MANUAL).
        setCacheable(true).list();

        if (l.size() == 1){
            newDept = (Department) l.get(0);
        }
    }
    return(newDept);
}
DepartmentalInstructor.java 文件源码 项目:unitimes 阅读 29 收藏 0 点赞 0 评论 0
public static DepartmentalInstructor findByPuidDepartmentId(String puid, Long deptId, org.hibernate.Session hibSession) {
    try {
    return (DepartmentalInstructor)hibSession.
        createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
        setString("puid", puid).
        setLong("deptId",deptId.longValue()).
        setCacheable(true).
        setFlushMode(FlushMode.MANUAL).
        uniqueResult();
    } catch (NonUniqueResultException e) {
        Debug.warning("There are two or more instructors with puid "+puid+" for department "+deptId+" -- returning the first one.");
        return (DepartmentalInstructor)hibSession.
            createQuery("select d from DepartmentalInstructor d where d.externalUniqueId=:puid and d.department.uniqueId=:deptId").
            setString("puid", puid).
            setLong("deptId",deptId.longValue()).
            setCacheable(true).
            setFlushMode(FlushMode.MANUAL).
            list().get(0);
    }
}
InstructorSchedulingDatabaseLoader.java 文件源码 项目:unitimes 阅读 31 收藏 0 点赞 0 评论 0
public void load() throws Exception {
    ApplicationProperties.setSessionId(iSessionId);
    org.hibernate.Session hibSession = null;
    Transaction tx = null;
    try {
        hibSession = TimetableManagerDAO.getInstance().createNewSession();
        hibSession.setCacheMode(CacheMode.IGNORE);
        hibSession.setFlushMode(FlushMode.COMMIT);

        tx = hibSession.beginTransaction(); 

        load(hibSession);

        tx.commit();
    } catch (Exception e) {
        iProgress.fatal("Unable to load input data, reason: " + e.getMessage(), e);
        tx.rollback();
    } finally {
        // here we need to close the session since this code may run in a separate thread
        if (hibSession != null && hibSession.isOpen()) hibSession.close();
    }
}
TimetableDatabaseLoader.java 文件源码 项目:unitimes 阅读 31 收藏 0 点赞 0 评论 0
public void load() {
    ApplicationProperties.setSessionId(iSessionId);
    org.hibernate.Session hibSession = null;
    Transaction tx = null;
    try {
        hibSession = TimetableManagerDAO.getInstance().getSession();
        hibSession.setCacheMode(CacheMode.IGNORE);
        hibSession.setFlushMode(FlushMode.COMMIT);

        tx = hibSession.beginTransaction(); 

        load(hibSession);

        tx.commit();
    } catch (Exception e) {
        iProgress.message(msglevel("loadFailed", Progress.MSGLEVEL_FATAL), "Unable to load input data, reason:"+e.getMessage(),e);
        tx.rollback();
    } finally {
        // here we need to close the session since this code may run in a separate thread
        if (hibSession!=null && hibSession.isOpen()) hibSession.close();
    }
}
EventImport.java 文件源码 项目:unitimes 阅读 27 收藏 0 点赞 0 评论 0
private Room findRoom(String buildingAbbv, String roomNumber){
    Room room = null;
    if (room == null) {
        List rooms =  this.
        getHibSession().
        createQuery("select distinct r from Room as r where r.roomNumber=:roomNbr and r.building.abbreviation = :building").
        setString("building", buildingAbbv).
        setString("roomNbr", roomNumber).
        setCacheable(true).
        setFlushMode(FlushMode.MANUAL).
        list();
        if (rooms != null && rooms.size() > 0){
            room = (Room) rooms.iterator().next();
        }
    }
    return(room);
}
HibernateJpaDialect.java 文件源码 项目:spring4-understanding 阅读 28 收藏 0 点赞 0 评论 0
protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
    FlushMode flushMode = session.getFlushMode();
    if (readOnly) {
        // We should suppress flushing for a read-only transaction.
        if (!flushMode.equals(FlushMode.MANUAL)) {
            session.setFlushMode(FlushMode.MANUAL);
            return flushMode;
        }
    }
    else {
        // We need AUTO or COMMIT for a non-read-only transaction.
        if (flushMode.lessThan(FlushMode.COMMIT)) {
            session.setFlushMode(FlushMode.AUTO);
            return flushMode;
        }
    }
    // No FlushMode change needed...
    return null;
}
SpringSessionSynchronization.java 文件源码 项目:spring4-understanding 阅读 36 收藏 0 点赞 0 评论 0
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();
        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.NEVER/MANUAL.
        if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
            try {
                SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            }
            catch (HibernateException ex) {
                throw translateException(ex);
            }
        }
    }
}
HibernateTransactionManager.java 文件源码 项目:spring4-understanding 阅读 30 收藏 0 点赞 0 评论 0
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
    if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
        HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
        Session session = txObject.getSessionHolder().getSession();
        if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
            logger.debug("Performing an early flush for Hibernate transaction");
            try {
                session.flush();
            }
            catch (HibernateException ex) {
                throw convertHibernateAccessException(ex);
            }
            finally {
                session.setFlushMode(FlushMode.MANUAL);
            }
        }
    }
}
OpenSessionInViewTests.java 文件源码 项目:spring4-understanding 阅读 30 收藏 0 点赞 0 评论 0
@Test
public void testOpenSessionInterceptor() throws Exception {
    final SessionFactory sf = mock(SessionFactory.class);
    final Session session = mock(Session.class);

    OpenSessionInterceptor interceptor = new OpenSessionInterceptor();
    interceptor.setSessionFactory(sf);

    Runnable tb = new Runnable() {
        @Override
        public void run() {
            assertTrue(TransactionSynchronizationManager.hasResource(sf));
            assertEquals(session, SessionFactoryUtils.getSession(sf, false));
        }
    };
    ProxyFactory pf = new ProxyFactory(tb);
    pf.addAdvice(interceptor);
    Runnable tbProxy = (Runnable) pf.getProxy();

    given(sf.openSession()).willReturn(session);
    given(session.isOpen()).willReturn(true);
    tbProxy.run();
    verify(session).setFlushMode(FlushMode.MANUAL);
    verify(session).close();
}
HibernateInterceptorTests.java 文件源码 项目:spring4-understanding 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void testInterceptorWithThreadBoundAndFlushEager() throws HibernateException {
    given(session.isOpen()).willReturn(true);
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);

    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    HibernateInterceptor interceptor = new HibernateInterceptor();
    interceptor.setFlushMode(HibernateInterceptor.FLUSH_EAGER);
    interceptor.setSessionFactory(sessionFactory);
    try {
        interceptor.invoke(invocation);
    }
    catch (Throwable t) {
        fail("Should not have thrown Throwable: " + t.getMessage());
    }
    finally {
        TransactionSynchronizationManager.unbindResource(sessionFactory);
    }

    verify(session).flush();
}
HibernateInterceptorTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testInterceptorWithThreadBoundAndFlushEagerSwitch() throws HibernateException {
    given(session.isOpen()).willReturn(true);
    given(session.getFlushMode()).willReturn(FlushMode.NEVER);

    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    HibernateInterceptor interceptor = new HibernateInterceptor();
    interceptor.setFlushMode(HibernateInterceptor.FLUSH_EAGER);
    interceptor.setSessionFactory(sessionFactory);
    try {
        interceptor.invoke(invocation);
    }
    catch (Throwable t) {
        fail("Should not have thrown Throwable: " + t.getMessage());
    }
    finally {
        TransactionSynchronizationManager.unbindResource(sessionFactory);
    }

    InOrder ordered = inOrder(session);
    ordered.verify(session).setFlushMode(FlushMode.AUTO);
    ordered.verify(session).flush();
    ordered.verify(session).setFlushMode(FlushMode.NEVER);
}
HibernateInterceptorTests.java 文件源码 项目:spring4-understanding 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void testInterceptorWithThreadBoundAndFlushCommit() {
    given(session.isOpen()).willReturn(true);
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);

    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    HibernateInterceptor interceptor = new HibernateInterceptor();
    interceptor.setSessionFactory(sessionFactory);
    interceptor.setFlushMode(HibernateInterceptor.FLUSH_COMMIT);
    try {
        interceptor.invoke(invocation);
    }
    catch (Throwable t) {
        fail("Should not have thrown Throwable: " + t.getMessage());
    }
    finally {
        TransactionSynchronizationManager.unbindResource(sessionFactory);
    }

    InOrder ordered = inOrder(session);
    ordered.verify(session).setFlushMode(FlushMode.COMMIT);
    ordered.verify(session).setFlushMode(FlushMode.AUTO);
    verify(session, never()).flush();
}
HibernateInterceptorTests.java 文件源码 项目:spring4-understanding 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void testInterceptorWithThreadBoundAndFlushAlways() {
    given(session.isOpen()).willReturn(true);
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);

    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    HibernateInterceptor interceptor = new HibernateInterceptor();
    interceptor.setSessionFactory(sessionFactory);
    interceptor.setFlushMode(HibernateInterceptor.FLUSH_ALWAYS);
    try {
        interceptor.invoke(invocation);
    }
    catch (Throwable t) {
        fail("Should not have thrown Throwable: " + t.getMessage());
    }
    finally {
        TransactionSynchronizationManager.unbindResource(sessionFactory);
    }

    InOrder ordered = inOrder(session);
    ordered.verify(session).setFlushMode(FlushMode.ALWAYS);
    ordered.verify(session).setFlushMode(FlushMode.AUTO);
    verify(session, never()).flush();
}
SpringSessionSynchronization.java 文件源码 项目:spring4-understanding 阅读 48 收藏 0 点赞 0 评论 0
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();
        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.MANUAL.
        if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
            try {
                SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            }
            catch (HibernateException ex) {
                throw SessionFactoryUtils.convertHibernateAccessException(ex);
            }
        }
    }
}
SpringSessionSynchronization.java 文件源码 项目:spring4-understanding 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
    if (!readOnly) {
        Session session = getCurrentSession();
        // Read-write transaction -> flush the Hibernate Session.
        // Further check: only flush when not FlushMode.MANUAL.
        if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
            try {
                SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
                session.flush();
            }
            catch (HibernateException ex) {
                throw SessionFactoryUtils.convertHibernateAccessException(ex);
            }
        }
    }
}
SpringSessionContext.java 文件源码 项目:lemon 阅读 30 收藏 0 点赞 0 评论 0
public Session currentSession() throws HibernateException {
    Object value = TransactionSynchronizationManager
            .getResource(this.sessionFactory);

    if (value instanceof Session) {
        return (Session) value;
    } else if (value instanceof SessionHolder) {
        SessionHolder sessionHolder = (SessionHolder) value;
        Session session = sessionHolder.getSession();

        if (TransactionSynchronizationManager.isSynchronizationActive()
                && !sessionHolder.isSynchronizedWithTransaction()) {
            TransactionSynchronizationManager
                    .registerSynchronization(new SpringSessionSynchronization(
                            sessionHolder, this.sessionFactory));
            sessionHolder.setSynchronizedWithTransaction(true);

            // Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
            // with FlushMode.MANUAL, which needs to allow flushing within the transaction.
            FlushMode flushMode = session.getFlushMode();

            if (FlushMode.isManualFlushMode(flushMode)
                    && !TransactionSynchronizationManager
                            .isCurrentTransactionReadOnly()) {
                session.setFlushMode(FlushMode.AUTO);
                sessionHolder.setPreviousFlushMode(flushMode);
            }
        }

        return session;
    } else {
        throw new HibernateException("No Session found for current thread");
    }
}
OpenSessionInterceptor.java 文件源码 项目:lams 阅读 39 收藏 0 点赞 0 评论 0
/**
 * Open a Session for the SessionFactory that this interceptor uses.
 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
 * method and sets the {@link Session}'s flush mode to "MANUAL".
 * @return the Session to use
 * @throws DataAccessResourceFailureException if the Session could not be created
 * @see org.hibernate.FlushMode#MANUAL
 */
protected Session openSession() throws DataAccessResourceFailureException {
    try {
        Session session = getSessionFactory().openSession();
        session.setFlushMode(FlushMode.MANUAL);
        return session;
    }
    catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}
OpenSessionInViewInterceptor.java 文件源码 项目:lams 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Open a Session for the SessionFactory that this interceptor uses.
 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
 * method and sets the {@link Session}'s flush mode to "MANUAL".
 * @return the Session to use
 * @throws DataAccessResourceFailureException if the Session could not be created
 * @see org.hibernate.FlushMode#MANUAL
 */
protected Session openSession() throws DataAccessResourceFailureException {
    try {
        Session session = getSessionFactory().openSession();
        session.setFlushMode(FlushMode.MANUAL);
        return session;
    }
    catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}
OpenSessionInViewFilter.java 文件源码 项目:lams 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Open a Session for the SessionFactory that this filter uses.
 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
 * method and sets the {@link Session}'s flush mode to "MANUAL".
 * @param sessionFactory the SessionFactory that this filter uses
 * @return the Session to use
 * @throws DataAccessResourceFailureException if the Session could not be created
 * @see org.hibernate.FlushMode#MANUAL
 */
protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
    try {
        Session session = sessionFactory.openSession();
        session.setFlushMode(FlushMode.MANUAL);
        return session;
    }
    catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}
SpringJtaSessionContext.java 文件源码 项目:lams 阅读 29 收藏 0 点赞 0 评论 0
@Override
protected Session buildOrObtainSession() {
    Session session = super.buildOrObtainSession();
    if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
        session.setFlushMode(FlushMode.MANUAL);
    }
    return session;
}
OpenSessionInterceptor.java 文件源码 项目:lams 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Open a Session for the SessionFactory that this interceptor uses.
 * <p>The default implementation delegates to the {@link SessionFactory#openSession}
 * method and sets the {@link Session}'s flush mode to "MANUAL".
 * @return the Session to use
 * @throws DataAccessResourceFailureException if the Session could not be created
 * @see org.hibernate.FlushMode#MANUAL
 */
protected Session openSession() throws DataAccessResourceFailureException {
    try {
        Session session = getSessionFactory().openSession();
        session.setFlushMode(FlushMode.MANUAL);
        return session;
    }
    catch (HibernateException ex) {
        throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号