org.springframework.orm.hibernate4.LocalSessionFactoryBean Java Examples
The following examples show how to use
org.springframework.orm.hibernate4.LocalSessionFactoryBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryTestConfig.java From Project with Apache License 2.0 | 6 votes |
@Bean public SessionFactory sessionFactoryBean() { try { LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean(); lsfb.setDataSource(dataSource()); lsfb.setPackagesToScan("spittr.domain"); Properties props = new Properties(); props.setProperty("dialect", "org.hibernate.dialect.H2Dialect"); lsfb.setHibernateProperties(props); lsfb.afterPropertiesSet(); SessionFactory object = lsfb.getObject(); return object; } catch (IOException e) { return null; } }
Example #2
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 6 votes |
private BeanDefinition buildSessionFactoryBeanDefinition(Element element, String name, BeanDefinitionParserDelegate beanDefinitionParserDelegate, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SESSION_FACTORY_SUFFIX); beanDefinition.setBeanClass(LocalSessionFactoryBean.class); beanDefinition.setParentName(SESSION_FACTORY_PARENT_BEAN_NAME); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dataSource", new RuntimeBeanReference(name + DATA_SOURCE_SUFFIX)); if (element.hasAttribute(TABLE_PREFIX_NAME) && !StringUtil.isEmpty(element.getAttribute(TABLE_PREFIX_NAME))) { AbstractBeanDefinition namingStrategyBeanDefinition = new GenericBeanDefinition(); String randomBeanName = UUID.randomUUID().toString(); namingStrategyBeanDefinition.setAttribute(ID_ATTRIBUTE, randomBeanName); namingStrategyBeanDefinition.setBeanClass(HibernateNamingStrategy.class); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); mutablePropertyValues.add("prefix", element.getAttribute(TABLE_PREFIX_NAME)); namingStrategyBeanDefinition.setPropertyValues(mutablePropertyValues); beanDefinitionRegistry.registerBeanDefinition(randomBeanName, namingStrategyBeanDefinition); propertyValues.addPropertyValue("namingStrategy", new RuntimeBeanReference(randomBeanName)); } beanDefinition.setPropertyValues(propertyValues); beanDefinitionParserDelegate.parsePropertyElements(element, beanDefinition); return beanDefinition; }
Example #3
Source File: RecoverableSessionFactoryBean.java From lemon with Apache License 2.0 | 6 votes |
public void afterPropertiesSet() throws IOException { long startTime = System.currentTimeMillis(); // init SessionFactoryWrapper sessionFactoryWrapper = new SessionFactoryWrapper(); try { // init LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); localSessionFactoryBean.setDataSource(dataSource); localSessionFactoryBean.setHibernateProperties(hibernateProperties); localSessionFactoryBean.setPackagesToScan(packagesToScan); localSessionFactoryBean.afterPropertiesSet(); SessionFactory sessionFactory = localSessionFactoryBean.getObject(); sessionFactoryWrapper.setSessionFactory(sessionFactory); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } long endTime = System.currentTimeMillis(); logger.info("hibernate init cost {} ms", (endTime - startTime)); }
Example #4
Source File: DbTestContext.java From OpERP with MIT License | 6 votes |
/** * * This setups the session factory */ @Bean public LocalSessionFactoryBean sessionFactory(Environment environment, DataSource dataSource) { /** * * Getting packageOfModelBean from package of message bean * */ LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean .setHibernateProperties(buildHibernateProperties(environment)); factoryBean.setPackagesToScan(packagesToScan); return factoryBean; }
Example #5
Source File: HibernateTransactionManagerConfiguration.java From hypersistence-optimizer with Apache License 2.0 | 5 votes |
@Bean public LocalSessionFactoryBean originalSessionFactory() { LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); localSessionFactoryBean.setDataSource(dataSource()); localSessionFactoryBean.setPackagesToScan(packagesToScan()); localSessionFactoryBean.setHibernateProperties(additionalProperties()); return localSessionFactoryBean; }
Example #6
Source File: GreetingServiceConfig.java From blog with Apache License 2.0 | 5 votes |
@Bean public LocalSessionFactoryBean getSessionFactory(DataSource dataSource, @Qualifier("hibernateProperties") Properties hibernateProperties) { LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean(); lsfb.setDataSource(dataSource); lsfb.setPackagesToScan("com.link_intersystems.examples.domain"); return lsfb; }
Example #7
Source File: GreetingServiceConfig.java From blog with Apache License 2.0 | 5 votes |
@Bean public LocalSessionFactoryBean getSessionFactory(DataSource dataSource, @Qualifier("hibernateProperties") Properties hibernateProperties) { LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean(); lsfb.setDataSource(dataSource); lsfb.setPackagesToScan("com.link_intersystems.examples.domain"); return lsfb; }
Example #8
Source File: SpringConfig.java From quickperf with Apache License 2.0 | 4 votes |
@Bean public PlatformTransactionManager hibernateTransactionManager(LocalSessionFactoryBean sessionFactory) { HibernateTransactionManager transactionManager = new HibernateTransactionManager(); transactionManager.setSessionFactory(sessionFactory.getObject()); return transactionManager; }