这是一个有点老的问题,但想正确回答。
通过将属性名称更改hibernate.current_session_context_class
为current_session_context_class
, 强制默认JTASessionContext
。
下面的片段来自 hibernate SessionFactoryImpl
。顺便说一句,Environment.CURRENT_SESSION_CONTEXT_CLASS
是"hibernate.current_session_context_class"
。ThreadLocalSessionContext
导致这个问题。
private CurrentSessionContext buildCurrentSessionContext() {
String impl = (String) properties.get( Environment.CURRENT_SESSION_CONTEXT_CLASS );
// for backward-compatibility
if ( impl == null ) {
if ( canAccessTransactionManager() ) {
impl = "jta";
}
else {
return null;
}
}
if ( "jta".equals( impl ) ) {
// if ( ! transactionFactory().compatibleWithJtaSynchronization() ) {
// LOG.autoFlushWillNotWork();
// }
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 = serviceRegistry.getService( ClassLoaderService.class ).classForName( impl );
return (CurrentSessionContext)
implClass.getConstructor( new Class[] { SessionFactoryImplementor.class } )
.newInstance( this );
}
catch( Throwable t ) {
LOG.unableToConstructCurrentSessionContext( impl, t );
return null;
}
}
}
请检查ThreadLocalSessionContext.TransactionProtectionWrapper.invoke