/** * Create a new SpringSessionContext for the given Hibernate SessionFactory. * @param sessionFactory the SessionFactory to provide current Sessions for */ public SpringSessionContext(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class); TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager(); this.jtaSessionContext = (transactionManager != null ? new SpringJtaSessionContext(sessionFactory) : null); }
private boolean canAccessTransactionManager() { try { return serviceRegistry.getService(JtaPlatform.class) .retrieveTransactionManager() != null; } catch (Exception e) { return false; } }
/** Get JBoss TM out of Hibernate */ public static TransactionManager extractJBossTransactionManager(EntityManagerFactory factory) { if (log.isDebugEnabled()) log.debug("TransactionManager를 꺼냅니다."); SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) ((HibernateEntityManagerFactory) factory).getSessionFactory(); return sessionFactory.getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager(); }
/** {@inheritDoc} */ @Nullable @Override protected ServiceRegistryBuilder registryBuilder() { ServiceRegistryBuilder builder = new ServiceRegistryBuilder(); DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl(); BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source. dataSrc.setTransactionManager(jotm.getTransactionManager()); dataSrc.setDefaultAutoCommit(false); JdbcDataSource h2DataSrc = new JdbcDataSource(); h2DataSrc.setURL(CONNECTION_URL); dataSrc.setXaDataSourceInstance(h2DataSrc); connProvider.setDataSource(dataSrc); connProvider.configure(Collections.emptyMap()); builder.addService(ConnectionProvider.class, connProvider); builder.addService(JtaPlatform.class, new TestJtaPlatform()); builder.addService(TransactionFactory.class, new JtaTransactionFactory()); return builder; }