Java Code Examples for org.springframework.orm.jpa.JpaTransactionManager

The following are top voted examples for showing how to use org.springframework.orm.jpa.JpaTransactionManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cas-5.1.0   File: JdbcMultifactorAuthnTrustConfiguration.java   Source Code and License 6 votes vote down vote up
@Autowired
@Bean
public PlatformTransactionManager transactionManagerMfaAuthnTrust(
        @Qualifier("mfaTrustedAuthnEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
 
Example 2
Project: cas-5.1.0   File: JpaServiceRegistryConfiguration.java   Source Code and License 6 votes vote down vote up
@Autowired
@Bean
public PlatformTransactionManager transactionManagerServiceReg(@Qualifier("serviceEntityManagerFactory")
                                                               final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
 
Example 3
Project: FHIR-CQL-ODM-service   File: FhirServerTestConfigDstu3.java   Source Code and License 6 votes vote down vote up
/**
	 * This interceptor adds some pretty syntax highlighting in responses when a browser is detected
	 */
/*	@Bean(autowire = Autowire.BY_TYPE)
	public IServerInterceptor responseHighlighterInterceptor() {
		ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor();
		return retVal;
	}*/

	/*	@Bean(autowire = Autowire.BY_TYPE)
	public IServerInterceptor subscriptionSecurityInterceptor() {
		SubscriptionsRequireManualActivationInterceptorDstu3 retVal = new SubscriptionsRequireManualActivationInterceptorDstu3();
		return retVal;
	}*/

	@Bean
	public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
		JpaTransactionManager retVal = new JpaTransactionManager();
		retVal.setEntityManagerFactory(entityManagerFactory);
		return retVal;
	}
 
Example 4
Project: FHIR-CQL-ODM-service   File: FhirServerTestConfigDstu3.java   Source Code and License 6 votes vote down vote up
/**
	 * This interceptor adds some pretty syntax highlighting in responses when a browser is detected
	 */
/*	@Bean(autowire = Autowire.BY_TYPE)
	public IServerInterceptor responseHighlighterInterceptor() {
		ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor();
		return retVal;
	}*/

	/*	@Bean(autowire = Autowire.BY_TYPE)
	public IServerInterceptor subscriptionSecurityInterceptor() {
		SubscriptionsRequireManualActivationInterceptorDstu3 retVal = new SubscriptionsRequireManualActivationInterceptorDstu3();
		return retVal;
	}*/

	@Bean
	public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
		JpaTransactionManager retVal = new JpaTransactionManager();
		retVal.setEntityManagerFactory(entityManagerFactory);
		return retVal;
	}
 
Example 5
Project: atsea-sample-shop-app   File: JpaConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
@Autowired
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
	JpaTransactionManager txManager = new JpaTransactionManager();
	txManager.setEntityManagerFactory(emf);
	return txManager;
}
 
Example 6
Project: spring4-understanding   File: PersistenceContextTransactionTests.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	factory = mock(EntityManagerFactory.class);
	manager = mock(EntityManager.class);
	tx = mock(EntityTransaction.class);

	JpaTransactionManager tm = new JpaTransactionManager(factory);
	tt = new TransactionTemplate(tm);

	given(factory.createEntityManager()).willReturn(manager);
	given(manager.getTransaction()).willReturn(tx);
	given(manager.isOpen()).willReturn(true);

	bean = new EntityManagerHoldingBean();
	@SuppressWarnings("serial")
	PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {
		@Override
		protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) {
			return factory;
		}
	};
	pabpp.postProcessPropertyValues(null, null, bean, "bean");

	assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
 
Example 7
Project: spring4-understanding   File: PersistenceContextTransactionTests.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	factory = mock(EntityManagerFactory.class);
	manager = mock(EntityManager.class);
	tx = mock(EntityTransaction.class);

	JpaTransactionManager tm = new JpaTransactionManager(factory);
	tt = new TransactionTemplate(tm);

	given(factory.createEntityManager()).willReturn(manager);
	given(manager.getTransaction()).willReturn(tx);
	given(manager.isOpen()).willReturn(true);

	bean = new EntityManagerHoldingBean();
	@SuppressWarnings("serial")
	PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {
		@Override
		protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) {
			return factory;
		}
	};
	pabpp.postProcessPropertyValues(null, null, bean, "bean");

	assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
 
Example 8
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: SecurityAutoConfigurationTests.java   Source Code and License 6 votes vote down vote up
@Test
public void testJpaCoexistsHappily() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.initialize:false");
	this.context.register(EntityConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
			SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
	// This can fail if security @Conditionals force early instantiation of the
	// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
	this.context.refresh();
	assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
 
Example 9
Project: spring-boot-concourse   File: SecurityAutoConfigurationTests.java   Source Code and License 6 votes vote down vote up
@Test
public void testJpaCoexistsHappily() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.initialize:false");
	this.context.register(EntityConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
			SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
	// This can fail if security @Conditionals force early instantiation of the
	// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
	this.context.refresh();
	assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
 
Example 10
Project: Camel   File: JpaComponentTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testJpaComponentEMFandTM() throws Exception {
    JpaComponent comp = new JpaComponent();
    comp.setCamelContext(context);
    assertNull(comp.getEntityManagerFactory());
    assertNull(comp.getTransactionManager());

    EntityManagerFactory fac = Persistence.createEntityManagerFactory("camel");
    JpaTransactionManager tm = new JpaTransactionManager(fac);
    tm.afterPropertiesSet();

    comp.setEntityManagerFactory(fac);
    comp.setTransactionManager(tm);

    assertSame(fac, comp.getEntityManagerFactory());
    assertSame(tm, comp.getTransactionManager());

    JpaEndpoint jpa = (JpaEndpoint) comp.createEndpoint("jpa://" + SendEmail.class.getName());
    assertNotNull(jpa);
    assertNotNull(jpa.getEntityType());
}
 
Example 11
Project: Camel   File: JpaEndpointTest.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * @deprecated
 */
@Deprecated
@Test
public void testJpaEndpointCtrUrlEMFandTM() throws Exception {
    EntityManagerFactory fac = Persistence.createEntityManagerFactory("camel");
    JpaTransactionManager tm = new JpaTransactionManager(fac);
    tm.afterPropertiesSet();

    JpaEndpoint jpa = new JpaEndpoint("jpa://org.apache.camel.examples.SendEmail", fac, tm);
    jpa.setEntityType(SendEmail.class);

    assertSame(fac, jpa.getEntityManagerFactory());
    assertSame(tm, jpa.getTransactionManager());

    assertEquals("jpa://org.apache.camel.examples.SendEmail", jpa.getEndpointUri());
    assertEquals("camel", jpa.getPersistenceUnit());
}
 
Example 12
Project: Camel   File: JpaEndpointTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testJpaEndpointCustomEMFandTM() throws Exception {
    EntityManagerFactory fac = Persistence.createEntityManagerFactory("camel");
    JpaTransactionManager tm = new JpaTransactionManager(fac);
    tm.afterPropertiesSet();

    JpaEndpoint jpa = new JpaEndpoint();
    jpa.setEntityType(SendEmail.class);

    jpa.setEntityManagerFactory(fac);
    jpa.setTransactionManager(tm);

    assertSame(fac, jpa.getEntityManagerFactory());
    assertSame(tm, jpa.getTransactionManager());

    assertEquals("jpa://org.apache.camel.examples.SendEmail", jpa.getEndpointUri());
    assertEquals("camel", jpa.getPersistenceUnit());
}
 
Example 13
Project: metaworks_framework   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveSiteById(final Long id, final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site site = siteDao.retrieve(id);
            if (persistentResult) {
                response[0] = site;
            } else {
                response[0] = getNonPersistentSite(site);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 14
Project: metaworks_framework   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveDefaultSite(final boolean persistentResult) {
    //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site defaultSite = siteDao.retrieveDefaultSite();
            if (persistentResult) {
                response[0] = defaultSite;
            } else {
                response[0] = getNonPersistentSite(defaultSite);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 15
Project: metaworks_framework   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected List<Site> findAllSites(final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final List<Site> response = new ArrayList<Site>();
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            List<Site> sites = siteDao.readAllActiveSites();
            for (Site site : sites) {
                if (persistentResult) {
                    response.add(site);
                } else {
                    response.add(getNonPersistentSite(site));
                }
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response;
}
 
Example 16
Project: SparkCommerce   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveSiteById(final Long id, final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site site = siteDao.retrieve(id);
            if (persistentResult) {
                response[0] = site;
            } else {
                response[0] = getNonPersistentSite(site);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 17
Project: SparkCommerce   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveDefaultSite(final boolean persistentResult) {
    //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site defaultSite = siteDao.retrieveDefaultSite();
            if (persistentResult) {
                response[0] = defaultSite;
            } else {
                response[0] = getNonPersistentSite(defaultSite);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 18
Project: SparkCommerce   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected List<Site> findAllSites(final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final List<Site> response = new ArrayList<Site>();
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            List<Site> sites = siteDao.readAllActiveSites();
            for (Site site : sites) {
                if (persistentResult) {
                    response.add(site);
                } else {
                    response.add(getNonPersistentSite(site));
                }
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response;
}
 
Example 19
Project: contestparser   File: SecurityAutoConfigurationTests.java   Source Code and License 6 votes vote down vote up
@Test
public void testJpaCoexistsHappily() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.datasource.initialize:false");
	this.context.register(EntityConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
			SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
	// This can fail if security @Conditionals force early instantiation of the
	// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
	this.context.refresh();
	assertNotNull(this.context.getBean(JpaTransactionManager.class));
}
 
Example 20
Project: blcdemo   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveSiteById(final Long id, final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    if (id == null) { return null; }
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site site = siteDao.retrieve(id);
            if (persistentResult) {
                response[0] = site;
            } else {
                response[0] = getNonPersistentSite(site);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 21
Project: blcdemo   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected Site retrieveDefaultSite(final boolean persistentResult) {
    //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final Site[] response = new Site[1];
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            Site defaultSite = siteDao.retrieveDefaultSite();
            if (persistentResult) {
                response[0] = defaultSite;
            } else {
                response[0] = getNonPersistentSite(defaultSite);
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response[0];
}
 
Example 22
Project: blcdemo   File: SiteServiceImpl.java   Source Code and License 6 votes vote down vote up
protected List<Site> findAllSites(final boolean persistentResult) {
  //Since the methods on this class are frequently called during regular page requests and transactions are expensive,
    //only run the operation under a transaction if there is not already an entity manager in the view
    final List<Site> response = new ArrayList<Site>();
    transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
        @Override
        public void execute() throws Throwable {
            List<Site> sites = siteDao.readAllActiveSites();
            for (Site site : sites) {
                if (persistentResult) {
                    response.add(site);
                } else {
                    response.add(getNonPersistentSite(site));
                }
            }
        }
    }, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));

    return response;
}
 
Example 23
Project: cas-5.1.0   File: JpaEventsConfiguration.java   Source Code and License 5 votes vote down vote up
@Autowired
@Bean
public PlatformTransactionManager transactionManagerEvents(@Qualifier("eventsEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
 
Example 24
Project: cas-5.1.0   File: GoogleAuthenticatorJpaConfiguration.java   Source Code and License 5 votes vote down vote up
@Autowired
@Bean
public PlatformTransactionManager transactionManagerGoogleAuthenticator(
        @Qualifier("googleAuthenticatorEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
 
Example 25
Project: cas-5.1.0   File: CasConsentJdbcConfiguration.java   Source Code and License 5 votes vote down vote up
@Autowired
@Bean
public PlatformTransactionManager transactionManagerConsent(
        @Qualifier("consentEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
 
Example 26
Project: Smart-Shopping   File: JPAConfig.java   Source Code and License 5 votes vote down vote up
@Bean
@Autowired
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) throws NamingException {
	JpaTransactionManager jpaTransaction = new JpaTransactionManager();
	jpaTransaction.setEntityManagerFactory(emf);
	return jpaTransaction;
}
 
Example 27
Project: amanda   File: RootContextConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
public PlatformTransactionManager jpaTransactionManager()
{
    return new JpaTransactionManager(
            this.entityManagerFactoryBean().getObject()
    );
}
 
Example 28
Project: JavaEE   File: AppConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name="transactionManager")
public JpaTransactionManager transactionManager(
        EntityManagerFactory entityManagerFactory) {
    JpaTransactionManager jtm = new JpaTransactionManager();
    jtm.setEntityManagerFactory(entityManagerFactory);
    return jtm;
}
 
Example 29
Project: JavaEE   File: AppConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name="transactionManager")
public JpaTransactionManager transactionManager(
        EntityManagerFactory entityManagerFactory) {
    JpaTransactionManager jtm = new JpaTransactionManager();
    jtm.setEntityManagerFactory(entityManagerFactory);
    return jtm;
}
 
Example 30
Project: JavaEE   File: AppConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name="transactionManager")
public JpaTransactionManager transactionManager(
        EntityManagerFactory entityManagerFactory) {
    JpaTransactionManager jtm = new JpaTransactionManager();
    jtm.setEntityManagerFactory(entityManagerFactory);
    return jtm;
}
 
Example 31
Project: holon-datastore-jpa   File: TransactionManagerConfigurator.java   Source Code and License 5 votes vote down vote up
/**
 * Configure given bean using provided configuration settings
 * @param tm Bean to configure
 */
public void configure(JpaTransactionManager tm) {

	// data context id
	if (dataContextId != null) {
		tm.setPersistenceUnitName(dataContextId);
	}

	// jpa properties
	if (jpaProperties != null) {
		tm.setJpaProperties(jpaProperties);
	}

	// settings
	if (transactionSynchronization != null) {
		tm.setTransactionSynchronization(transactionSynchronization);
	}
	if (defaultTimeout != null) {
		tm.setDefaultTimeout(defaultTimeout);
	}
	if (validateExistingTransaction != null) {
		tm.setValidateExistingTransaction(validateExistingTransaction);
	}
	if (globalRollbackOnParticipationFailure != null) {
		tm.setGlobalRollbackOnParticipationFailure(globalRollbackOnParticipationFailure);
	}
	if (failEarlyOnGlobalRollbackOnly != null) {
		tm.setFailEarlyOnGlobalRollbackOnly(failEarlyOnGlobalRollbackOnly);
	}
	if (rollbackOnCommitFailure != null) {
		tm.setRollbackOnCommitFailure(rollbackOnCommitFailure);
	}

}
 
Example 32
Project: jwala   File: AemJpaConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
public PlatformTransactionManager getPlatformTransactionManager(final EntityManagerFactory emf) {
    final JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setDefaultTimeout(ApplicationProperties.getAsInteger(JWALA_JTA_TRANSACTION_TIMEOUT, 30));
    transactionManager.setEntityManagerFactory(emf);
    return transactionManager;
}
 
Example 33
Project: jdblender   File: Config.java   Source Code and License 5 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setDataSource(dataSourceH2());
    txManager.setEntityManagerFactory(entityManagerFactory().getObject());
    return txManager;
}
 
Example 34
Project: BCDS   File: DatabaseConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Autowired
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
    JpaTransactionManager txManager = new JpaTransactionManager();
    JpaDialect jpaDialect = new HibernateJpaDialect();
    txManager.setEntityManagerFactory(entityManagerFactory);
    txManager.setJpaDialect(jpaDialect);
    return txManager;
}
 
Example 35
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: AbstractJpaAutoConfigurationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testEntityManagerCreated() throws Exception {
	setupTestConfiguration();
	this.context.refresh();
	assertThat(this.context.getBean(DataSource.class)).isNotNull();
	assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
 
Example 36
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: AbstractJpaAutoConfigurationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testDataSourceTransactionManagerNotCreated() throws Exception {
	this.context.register(DataSourceTransactionManagerAutoConfiguration.class);
	setupTestConfiguration();
	this.context.refresh();
	assertThat(this.context.getBean(DataSource.class)).isNotNull();
	assertThat(this.context.getBean("transactionManager"))
			.isInstanceOf(JpaTransactionManager.class);
}
 
Example 37
Project: spring-content   File: EnableJpaStoresTest.java   Source Code and License 5 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {

	JpaTransactionManager txManager = new JpaTransactionManager();
	txManager.setEntityManagerFactory(entityManagerFactory().getObject());
	return txManager;
}
 
Example 38
Project: Audit4j-Hibernate   File: PersistanceConfig.java   Source Code and License 5 votes vote down vote up
/**
 * Transaction manager.
 *
 * @return the platform transaction manager
 */
@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager tm = new JpaTransactionManager();
    tm.setEntityManagerFactory(this.entityManagerFactory().getObject());
    return tm;
}
 
Example 39
Project: StashThisBot   File: StashThisConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Autowired
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(emf);
    return txManager;
}
 
Example 40
Project: SpringMVCWithJavaConfig   File: JPAConfig.java   Source Code and License 5 votes vote down vote up
/**
 * 配置 Spring 事务管理器
 */
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
    JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
    jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
    return jpaTransactionManager;
}