org.hibernate.context.CurrentSessionContext Java Examples

The following examples show how to use org.hibernate.context.CurrentSessionContext. 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: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CurrentSessionContext buildCurrentSessionContext() {
	String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
	// for backward-compatability
	if ( impl == null && transactionManager != null ) {
		impl = "jta";
	}

	if ( impl == null ) {
		return null;
	}
	else if ( "jta".equals( impl ) ) {
		if ( settings.getTransactionFactory().areCallbacksLocalToHibernateTransactions() ) {
			log.warn( "JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()" );
		}
		return new JTASessionContext( this );
	}
	else if ( "thread".equals( impl ) ) {
		return new ThreadLocalSessionContext( this );
	}
	else if ( "managed".equals( impl ) ) {
		return new ManagedSessionContext( this );
	}
	else {
		try {
			Class implClass = ReflectHelper.classForName( impl );
			return ( CurrentSessionContext ) implClass
					.getConstructor( new Class[] { SessionFactoryImplementor.class } )
					.newInstance( new Object[] { this } );
		}
		catch( Throwable t ) {
			log.error( "Unable to construct current session context [" + impl + "]", t );
			return null;
		}
	}
}