Java Code Examples for org.springframework.orm.hibernate3.SessionFactoryUtils#releaseSession()

The following examples show how to use org.springframework.orm.hibernate3.SessionFactoryUtils#releaseSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenSessionInViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception {
	SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);

	OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
	interceptor.setSessionFactory(sf);
	interceptor.setSingleSession(false);

	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);

	interceptor.preHandle(this.webRequest);
	org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
	SessionFactoryUtils.releaseSession(sess, sf);

	// check that further invocations simply participate
	interceptor.preHandle(this.webRequest);

	interceptor.preHandle(this.webRequest);
	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.preHandle(this.webRequest);
	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	interceptor.postHandle(this.webRequest, null);
	interceptor.afterCompletion(this.webRequest, null);

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(session).close();
}
 
Example 2
Source File: HibernateDaoSupport.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Close the given Hibernate Session, created via this DAO's SessionFactory,
 * if it isn't bound to the thread (i.e. isn't a transactional Session).
 * <p>Typically used in plain Hibernate code, in combination with
 * {@link #getSession} and {@link #convertHibernateAccessException}.
 * @param session the Session to close
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#releaseSession
 * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage
 */
@Deprecated
protected final void releaseSession(Session session) {
	SessionFactoryUtils.releaseSession(session, getSessionFactory());
}