List of usage examples for org.hibernate.cfg AvailableSettings JTA_PLATFORM
String JTA_PLATFORM
To view the source code for org.hibernate.cfg AvailableSettings JTA_PLATFORM.
Click Source Link
From source file:org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.java
License:Apache License
@SuppressWarnings("deprecation") @Override/*from w ww .j ava 2 s . c om*/ public void addProviderProperties(Map properties, PersistenceUnitMetadata pu) { putPropertyIfAbsent(pu, properties, AvailableSettings.JPAQL_STRICT_COMPLIANCE, "true"); // JIPI-24 ignore jpql aliases case putPropertyIfAbsent(pu, properties, AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); putPropertyIfAbsent(pu, properties, AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "false"); putPropertyIfAbsent(pu, properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY, NAMING_STRATEGY_JPA_COMPLIANT_IMPL); putPropertyIfAbsent(pu, properties, AvailableSettings.SCANNER, HibernateArchiveScanner.class); properties.put(AvailableSettings.APP_CLASSLOADER, pu.getClassLoader()); putPropertyIfAbsent(pu, properties, AvailableSettings.JTA_PLATFORM, new JBossAppServerJtaPlatform(jtaManager)); putPropertyIfAbsent(pu, properties, org.hibernate.ejb.AvailableSettings.ENTITY_MANAGER_FACTORY_NAME, pu.getScopedPersistenceUnitName()); putPropertyIfAbsent(pu, properties, AvailableSettings.SESSION_FACTORY_NAME, pu.getScopedPersistenceUnitName()); if (!pu.getProperties().containsKey(AvailableSettings.SESSION_FACTORY_NAME)) { putPropertyIfAbsent(pu, properties, AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, Boolean.FALSE); } }
From source file:org.jboss.as.test.integration.hibernate.secondlevelcache.SFSB.java
License:Open Source License
@TransactionAttribute(TransactionAttributeType.NEVER) public void setupConfig() { // static {/*from w w w. j a va 2s . c om*/ try { //System.out.println("setupConfig: Current dir = " + (new File(".")).getCanonicalPath()); // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); sessionFactory = configuration.buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernate2LcacheStats.java
License:Open Source License
@TransactionAttribute(TransactionAttributeType.NEVER) public void setupConfig() { // static {/*from w w w. j a v a 2s. c om*/ try { //System.out.println("setupConfig: Current dir = " + (new File(".")).getCanonicalPath()); // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); // set property to enable statistics configuration.setProperty("hibernate.generate_statistics", "true"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); // build the serviceregistry sessionFactory = configuration.buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } //System.out.println("setupConfig: done"); }
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernateTransaction.java
License:Open Source License
public void setupConfig() { // static {/* www.java2 s .c o m*/ try { // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); configuration.setProperty("hibernate.listeners.envers.autoRegister", "false"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); sessionFactory = configuration.buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); // ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } }
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernatewithCriteriaSession.java
License:Open Source License
public void setupConfig() { // static {// ww w. j av a2s . c om try { // prepare the configuration Configuration configuration = new Configuration() .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class); configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS"); configuration.setProperty("hibernate.listeners.envers.autoRegister", "false"); // fetch the properties Properties properties = new Properties(); configuration = configuration.configure("hibernate.cfg.xml"); properties.putAll(configuration.getProperties()); Environment.verifyProperties(properties); ConfigurationHelper.resolvePlaceHolders(properties); // build the serviceregistry StandardServiceRegistryBuilder registry = new StandardServiceRegistryBuilder() .applySettings(properties); sessionFactory = configuration.buildSessionFactory(registry.build()); // build metamodel SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; MetamodelImpl.buildMetamodel(configuration.getClassMappings(), sfi); sessionFactory.getStatistics().setStatisticsEnabled(true); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); // ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } }
From source file:org.overlord.rtgov.common.jpa.JpaStore.java
License:Apache License
/** * This method returns a Session./*from w w w. ja v a 2 s. c om*/ * * @return The Session */ private Session getSession() { if (_persistenceUnit == null) { if (_sessionFactory == null) { final Configuration cfg = new Configuration().configure(_configXml); final Properties properties = RTGovProperties.getProperties(); if (_jndiProperty != null) { String prop = RTGovProperties.getProperty(_jndiProperty); if (prop != null) { properties.setProperty(AvailableSettings.DATASOURCE, prop); } } final String jtaPlatform = RTGovProperties.getProperty(JTA_PLATFORM_PROPERTY); if (jtaPlatform == null) { LOG.warning("JpaStore.jtaPlatform not set in overlord-rtgov.properties!"); _isJta = false; } else { properties.setProperty(AvailableSettings.JTA_PLATFORM, RTGovProperties.getProperty(JTA_PLATFORM_PROPERTY)); } cfg.getProperties().putAll(properties); _sessionFactory = cfg.buildSessionFactory(); } return _sessionFactory.openSession(); } else { // NOTE: For backward compatibility in EAP, I'm allowing the // continued use of a persistence unit. // Simply use it to create an EntityManager, then unwrap to the // native Hibernate Session. if (_entityManagerFactory == null) { final Properties properties = RTGovProperties.getProperties(); if (_jndiProperty != null) { properties.setProperty(AvailableSettings.DATASOURCE, RTGovProperties.getProperty(_jndiProperty)); } final String jtaPlatform = RTGovProperties.getProperty(JTA_PLATFORM_PROPERTY); if (jtaPlatform == null) { LOG.warning("JpaStore.jtaPlatform not set in overlord-rtgov.properties!"); _isJta = false; } else { properties.setProperty(AvailableSettings.JTA_PLATFORM, RTGovProperties.getProperty(JTA_PLATFORM_PROPERTY)); } _entityManagerFactory = Persistence.createEntityManagerFactory(_persistenceUnit, properties); } return _entityManagerFactory.createEntityManager().unwrap(Session.class); } }
From source file:org.springframework.orm.hibernate4.HibernateTransactionManagerTests.java
License:Apache License
@Test public void testSetJtaTransactionManager() throws Exception { DataSource ds = mock(DataSource.class); TransactionManager tm = mock(TransactionManager.class); UserTransaction ut = mock(UserTransaction.class); TransactionSynchronizationRegistry tsr = mock(TransactionSynchronizationRegistry.class); JtaTransactionManager jtm = new JtaTransactionManager(); jtm.setTransactionManager(tm);/*from ww w . j av a 2 s . c o m*/ jtm.setUserTransaction(ut); jtm.setTransactionSynchronizationRegistry(tsr); LocalSessionFactoryBuilder lsfb = new LocalSessionFactoryBuilder(ds); lsfb.setJtaTransactionManager(jtm); Object jtaPlatform = lsfb.getProperties().get(AvailableSettings.JTA_PLATFORM); assertNotNull(jtaPlatform); assertSame(tm, jtaPlatform.getClass().getMethod("retrieveTransactionManager").invoke(jtaPlatform)); assertSame(ut, jtaPlatform.getClass().getMethod("retrieveUserTransaction").invoke(jtaPlatform)); assertTrue( lsfb.getProperties().get(AvailableSettings.TRANSACTION_STRATEGY) instanceof CMTTransactionFactory); }
From source file:org.springframework.orm.hibernate4.HibernateTransactionManagerTests.java
License:Apache License
@Test public void testSetTransactionManager() throws Exception { DataSource ds = mock(DataSource.class); TransactionManager tm = mock(TransactionManager.class); LocalSessionFactoryBuilder lsfb = new LocalSessionFactoryBuilder(ds); lsfb.setJtaTransactionManager(tm);/*from w w w . ja v a2 s. c o m*/ Object jtaPlatform = lsfb.getProperties().get(AvailableSettings.JTA_PLATFORM); assertNotNull(jtaPlatform); assertSame(tm, jtaPlatform.getClass().getMethod("retrieveTransactionManager").invoke(jtaPlatform)); assertTrue( lsfb.getProperties().get(AvailableSettings.TRANSACTION_STRATEGY) instanceof CMTTransactionFactory); }
From source file:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.java
License:Apache License
/** * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager} * to be used with Hibernate, if any. Allows for using a Spring-managed transaction * manager for Hibernate 4's session and cache synchronization, with the * "hibernate.transaction.jta.platform" automatically set to it. Also sets * "hibernate.transaction.factory_class" to {@link CMTTransactionFactory}, * instructing Hibernate to interact with externally managed transactions. * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA * {@link TransactionManager} reference to be usable here, except for the WebSphere * case where we'll automatically set {@code WebSphereExtendedJtaPlatform} accordingly. * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform * setting to avoid meaningless double configuration. */// w ww . j a v a2s . com public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) { Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null"); if (jtaTransactionManager instanceof JtaTransactionManager) { boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager", getClass().getClassLoader()); if (webspherePresent) { getProperties().put(AvailableSettings.JTA_PLATFORM, ConfigurableJtaPlatform.getJtaPlatformBasePackage() + "internal.WebSphereExtendedJtaPlatform"); } else { JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager; if (jtaTm.getTransactionManager() == null) { throw new IllegalArgumentException( "Can only apply JtaTransactionManager which has a TransactionManager reference set"); } getProperties() .put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction(), jtaTm.getTransactionSynchronizationRegistry()) .getJtaPlatformProxy()); } } else if (jtaTransactionManager instanceof TransactionManager) { getProperties().put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null, null) .getJtaPlatformProxy()); } else { throw new IllegalArgumentException( "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName()); } getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory()); return this; }
From source file:org.springframework.orm.hibernate43.LocalSessionFactoryBuilder.java
License:Apache License
/** * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager} * to be used with Hibernate, if any. Allows for using a Spring-managed transaction * manager for Hibernate 4's session and cache synchronization, with the * "hibernate.transaction.jta.platform" automatically set to it. Also sets * "hibernate.transaction.factory_class" to {@link CMTTransactionFactory}, * instructing Hibernate to interact with externally managed transactions. * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA * {@link TransactionManager} reference to be usable here, except for the WebSphere * case where we'll automatically set {@link WebSphereExtendedJtaPlatform} accordingly. * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform * setting to avoid meaningless double configuration. *//*w w w.j av a 2s . c om*/ public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) { Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null"); if (jtaTransactionManager instanceof JtaTransactionManager) { boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager", getClass().getClassLoader()); if (webspherePresent) { getProperties().put(AvailableSettings.JTA_PLATFORM, new WebSphereExtendedJtaPlatform()); } else { JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager; if (jtaTm.getTransactionManager() == null) { throw new IllegalArgumentException( "Can only apply JtaTransactionManager which has a TransactionManager reference set"); } getProperties().put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction())); } } else if (jtaTransactionManager instanceof TransactionManager) { getProperties().put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null)); } else { throw new IllegalArgumentException( "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName()); } getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory()); return this; }