File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed 
spring-orm/src/main/java/org/springframework/orm/jpa/hibernate Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -171,9 +171,6 @@ else if (value instanceof EntityManagerHolder entityManagerHolder) {
171171	 * @return the current StatelessSession 
172172	 */ 
173173	public  static  StatelessSession  currentStatelessSession (SessionFactory  sessionFactory ) {
174- 		if  (!TransactionSynchronizationManager .isSynchronizationActive ()) {
175- 			throw  new  HibernateException ("Could not obtain transaction-synchronized Session for current thread" );
176- 		}
177174		Object  value  = TransactionSynchronizationManager .getResource (sessionFactory );
178175		if  (value  instanceof  StatelessSession  statelessSession ) {
179176			return  statelessSession ;
@@ -185,14 +182,20 @@ public static StatelessSession currentStatelessSession(SessionFactory sessionFac
185182			}
186183			holder  = sessionHolder ;
187184		}
188- 		StatelessSession  session  = sessionFactory .openStatelessSession (determineConnection (sessionFactory , holder ));
189- 		if  (holder  != null ) {
190- 			holder .setStatelessSession (session );
185+ 
186+ 		if  (TransactionSynchronizationManager .isSynchronizationActive ()) {
187+ 			StatelessSession  session  = sessionFactory .openStatelessSession (determineConnection (sessionFactory , holder ));
188+ 			if  (holder  != null ) {
189+ 				holder .setStatelessSession (session );
190+ 			}
191+ 			else  {
192+ 				bindSessionHolder (sessionFactory , new  SessionHolder (session ));
193+ 			}
194+ 			return  session ;
191195		}
192196		else  {
193- 			bindSessionHolder ( sessionFactory ,  new  SessionHolder ( session ) );
197+ 			throw  new  HibernateException ( "Could not obtain transaction-synchronized Session for current thread" );
194198		}
195- 		return  session ;
196199	}
197200
198201	private  static  void  bindSessionHolder (SessionFactory  sessionFactory , SessionHolder  holder ) {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments