public void setSession(Session session) { this.sessionHolder = new SessionHolder(session); this.newSessionHolder = true; this.newSession = true; }
public void setExistingSession(Session session) { this.sessionHolder = new SessionHolder(session); this.newSessionHolder = true; this.newSession = false; }
public void setSession(Session session) { this.sessionHolder = new SessionHolder(session); this.newSessionHolder = true; this.newSession = true; }
public void setExistingSession(Session session) { this.sessionHolder = new SessionHolder(session); this.newSessionHolder = true; this.newSession = false; }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); Assert.state(sf != null, "No SessionFactory set"); if (!TransactionSynchronizationManager.hasResource(sf)) { // New Session to be bound for the current method's scope... Session session = openSession(sf); try { TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session)); return invocation.proceed(); } finally { SessionFactoryUtils.closeSession(session); TransactionSynchronizationManager.unbindResource(sf); } } else { // Pre-bound Session found -> simply proceed. return invocation.proceed(); } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); Assert.state(sf != null, "No SessionFactory set"); if (!TransactionSynchronizationManager.hasResource(sf)) { // New Session to be bound for the current method's scope... Session session = openSession(sf); try { TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session)); return invocation.proceed(); } finally { SessionFactoryUtils.closeSession(session); TransactionSynchronizationManager.unbindResource(sf); } } else { // Pre-bound Session found -> simply proceed. return invocation.proceed(); } }
logger.debug("Opening Hibernate Session in OpenSessionInViewFilter"); Session session = openSession(sessionFactory); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
/** * Open a new Hibernate {@code Session} according and bind it to the thread via the * {@link TransactionSynchronizationManager}. */ @Override public void preHandle(WebRequest request) throws DataAccessException { String key = getParticipateAttributeName(); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); if (asyncManager.hasConcurrentResult() && applySessionBindingInterceptor(asyncManager, key)) { return; } if (TransactionSynchronizationManager.hasResource(obtainSessionFactory())) { // Do not modify the Session: just mark the request accordingly. Integer count = (Integer) request.getAttribute(key, WebRequest.SCOPE_REQUEST); int newCount = (count != null ? count + 1 : 1); request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); } else { logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor"); Session session = openSession(); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(obtainSessionFactory(), sessionHolder); AsyncRequestInterceptor asyncRequestInterceptor = new AsyncRequestInterceptor(obtainSessionFactory(), sessionHolder); asyncManager.registerCallableInterceptor(key, asyncRequestInterceptor); asyncManager.registerDeferredResultInterceptor(key, asyncRequestInterceptor); } }
logger.debug("Opening Hibernate Session in OpenSessionInViewFilter"); Session session = openSession(sessionFactory); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
/** * Open a new Hibernate {@code Session} according and bind it to the thread via the * {@link TransactionSynchronizationManager}. */ @Override public void preHandle(WebRequest request) throws DataAccessException { String key = getParticipateAttributeName(); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); if (asyncManager.hasConcurrentResult() && applySessionBindingInterceptor(asyncManager, key)) { return; } if (TransactionSynchronizationManager.hasResource(obtainSessionFactory())) { // Do not modify the Session: just mark the request accordingly. Integer count = (Integer) request.getAttribute(key, WebRequest.SCOPE_REQUEST); int newCount = (count != null ? count + 1 : 1); request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); } else { logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor"); Session session = openSession(); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(obtainSessionFactory(), sessionHolder); AsyncRequestInterceptor asyncRequestInterceptor = new AsyncRequestInterceptor(obtainSessionFactory(), sessionHolder); asyncManager.registerCallableInterceptor(key, asyncRequestInterceptor); asyncManager.registerDeferredResultInterceptor(key, asyncRequestInterceptor); } }
session.setFlushMode(FlushMode.MANUAL); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.registerSynchronization( new SpringSessionSynchronization(sessionHolder, this.sessionFactory, true));
private void bind(Session session) { Object sessionHolder = new org.springframework.orm.hibernate5.SessionHolder(session); TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder); }
session.setFlushMode(FlushMode.MANUAL); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.registerSynchronization( new SpringSessionSynchronization(sessionHolder, this.sessionFactory, true));
public static void bindSessionToThread( SessionFactory sessionFactory ) { Session session = sessionFactory.openSession(); TransactionSynchronizationManager.bindResource( sessionFactory, new SessionHolder( session ) ); }
private void bind(Session session) { Object sessionHolder = new org.springframework.orm.hibernate5.SessionHolder(session); TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder); }
private void bindSession() { SessionFactory sessionFactory = (SessionFactory) webApplicationContext.getBean( "sessionFactory" ); Session session = sessionFactory.openSession(); session.setHibernateFlushMode(FlushMode.ALWAYS); TransactionSynchronizationManager.bindResource( sessionFactory, new SessionHolder( session ) ); }
/** * Binds a Hibernate Session to the current thread. */ private void bindSession() { SessionFactory sessionFactory = (SessionFactory) getBean( "sessionFactory" ); Session session = sessionFactory.openSession(); TransactionSynchronizationManager.bindResource( sessionFactory, new SessionHolder( session ) ); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); Assert.state(sf != null, "No SessionFactory set"); if (!TransactionSynchronizationManager.hasResource(sf)) { // New Session to be bound for the current method's scope... Session session = openSession(sf); try { TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session)); return invocation.proceed(); } finally { SessionFactoryUtils.closeSession(session); TransactionSynchronizationManager.unbindResource(sf); } } else { // Pre-bound Session found -> simply proceed. return invocation.proceed(); } }
logger.debug("Opening Hibernate Session in OpenSessionInViewFilter"); Session session = openSession(sessionFactory); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
/** * Open a new Hibernate {@code Session} according and bind it to the thread via the * {@link TransactionSynchronizationManager}. */ @Override public void preHandle(WebRequest request) throws DataAccessException { String key = getParticipateAttributeName(); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); if (asyncManager.hasConcurrentResult() && applySessionBindingInterceptor(asyncManager, key)) { return; } if (TransactionSynchronizationManager.hasResource(obtainSessionFactory())) { // Do not modify the Session: just mark the request accordingly. Integer count = (Integer) request.getAttribute(key, WebRequest.SCOPE_REQUEST); int newCount = (count != null ? count + 1 : 1); request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); } else { logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor"); Session session = openSession(); SessionHolder sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(obtainSessionFactory(), sessionHolder); AsyncRequestInterceptor asyncRequestInterceptor = new AsyncRequestInterceptor(obtainSessionFactory(), sessionHolder); asyncManager.registerCallableInterceptor(key, asyncRequestInterceptor); asyncManager.registerDeferredResultInterceptor(key, asyncRequestInterceptor); } }