@@ -310,6 +310,7 @@ protected Object findLazyValue(PersistentCollection coll) {
310
310
return null ;
311
311
}
312
312
if (_sessionFactory != null ) {
313
+ // 08-Feb-2017, tatu: and not closing this is not problematic... ?
313
314
Session session = openTemporarySessionForLoading (coll );
314
315
initializeCollection (coll , session );
315
316
}
@@ -423,52 +424,14 @@ private Object convertToSet(Set<?> value) {
423
424
}
424
425
425
426
protected static class SessionReader {
426
-
427
- /**
428
- * Return changed from org.hibernate.resource.transaction.TransactionCoordinator
429
- * to org.hibernate.resource.transaction.spi.TransactionCoordinator
430
- */
431
- protected static final Method getTransactionCoordinatorMethod ;
432
- /**
433
- * Return changed from org.hibernate.resource.transaction.TransactionCoordinatorBuilder
434
- * to org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder
435
- */
436
- protected static final Method getTransactionCoordinatorBuilderMethod ;
437
- /**
438
- * Class changed from org.hibernate.resource.transaction.TransactionCoordinatorBuilder
439
- * to org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder
440
- */
441
- protected static final Method isJtaMethod ;
442
-
443
- static {
444
- try {
445
- getTransactionCoordinatorMethod = SessionImplementor .class .getMethod ("getTransactionCoordinator" );
446
- } catch (Exception e ) {
447
- // should never happen: the class and method exists in all versions of hibernate 5
448
- throw new RuntimeException (e );
449
- }
450
- try {
451
- getTransactionCoordinatorBuilderMethod = Hibernate5Version .getTransactionCoordinatorClass ().getMethod ("getTransactionCoordinatorBuilder" );
452
- } catch (Exception e ) {
453
- // should never happen
454
- throw new RuntimeException (e );
455
- }
456
- try {
457
- isJtaMethod = Hibernate5Version .getTransactionCoordinatorClass ().getMethod ("isJta" );
458
- } catch (Exception e ) {
459
- // should never happen
460
- throw new RuntimeException (e );
461
- }
462
- }
463
-
464
427
public static boolean isJTA (Session session ) {
465
428
try {
466
- Object transactionCoordinator = getTransactionCoordinatorMethod . invoke ( session ) ;
467
- Object transactionCoordinatorBuilder = getTransactionCoordinatorBuilderMethod . invoke ( transactionCoordinator );
468
- return ( boolean ) isJtaMethod . invoke ( transactionCoordinatorBuilder ) ;
469
- } catch (Exception e ) {
470
- // Should never happen
471
- throw new RuntimeException ( e ) ;
429
+ EntityManager em = ( EntityManager ) session ;
430
+ em . getTransaction ( );
431
+ return false ;
432
+ } catch (IllegalStateException e ) {
433
+ // EntityManager is required to throw an IllegalStateException if it's JTA-managed
434
+ return true ;
472
435
}
473
436
}
474
437
}
0 commit comments