当前位置: 首页>>代码示例>>Java>>正文


Java LocalSessionFactoryBean类代码示例

本文整理汇总了Java中org.springframework.orm.hibernate4.LocalSessionFactoryBean的典型用法代码示例。如果您正苦于以下问题:Java LocalSessionFactoryBean类的具体用法?Java LocalSessionFactoryBean怎么用?Java LocalSessionFactoryBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocalSessionFactoryBean类属于org.springframework.orm.hibernate4包,在下文中一共展示了LocalSessionFactoryBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterPropertiesSet

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
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));
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:25,代码来源:RecoverableSessionFactoryBean.java

示例2: hibernate5SessionFactoryBean

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean(name = "sessionFactory")
public LocalSessionFactoryBean hibernate5SessionFactoryBean(){
    LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    localSessionFactoryBean.setDataSource(dataSource);
    localSessionFactoryBean.setAnnotatedClasses(
           UserAccount.class
    );

    /** Porperties dla mysql. Wszystekie są zawarte w application.properties ale niech narazie bd bo nie wiem czy
     * na pewno są wszystkie
     **/
    /*
    Properties properties = new Properties();
    properties.put("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
    //properties.put("hibernate.current_session_context_class","thread");
    properties.put("hibernate.hbm2ddl.auto","update");

    localSessionFactoryBean.setHibernateProperties(properties);

    */
    return localSessionFactoryBean;
}
 
开发者ID:PollubCafe,项目名称:Project-X,代码行数:23,代码来源:GeneralConfig.java

示例3: obtainSessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
/**
 * 生成一个新的SessionFactory,将模块的的model解析.
 * 这里将来可以做成从资源配置文件中动态解析生成.
 * @param entityClasses
 * @return
 */
private SessionFactory obtainSessionFactory(Collection<Class> entityClasses){
    LocalSessionFactoryBean localSessionFactoryBean =(LocalSessionFactoryBean) SpringContextUtil.getBean("&defaultSessionFactory");
    Configuration configuration = localSessionFactoryBean.getConfiguration();
    synchronized(configuration){//避免并发操作导致configuration重复添加相同的entityClass
        for(Class entityClass:entityClasses){
            if(configuration.getClassMapping(entityClass.getName())==null){
                configuration.addAnnotatedClass(entityClass);
            }
        }
    }
    Thread.currentThread().setContextClassLoader(this);//设置当前的Classloader不然会报找不到类的错误
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    SessionFactory newSessionFactory = configuration.buildSessionFactory(serviceRegistry);
    log.info("为模块中{}个类重新生成一个新的SessionFactory",entityClasses.size());
    Map<String,SessionFactory> sessionFactoryMap =(Map<String,SessionFactory>) SpringContextUtil.getBean("sessionFactoryMap");
    sessionFactoryMap.put(getModulesBean().getName(),newSessionFactory);
    return newSessionFactory;
}
 
开发者ID:hyberbin,项目名称:hyberbin-osgi,代码行数:25,代码来源:SpringModuleLoaderImpl.java

示例4: sessionFactoryBeanTest

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
@Profile("test")
public SessionFactory sessionFactoryBeanTest(DataSource dataSource) {
    try {
        LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
        lsfb.setDataSource(dataSource);
        lsfb.setPackagesToScan("com.opteral.springsms.model");
        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;
    }
}
 
开发者ID:amalio,项目名称:spring-json-sms-gateway,代码行数:18,代码来源:DataConfig.java

示例5: sessionFactoryBean

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
@Profile("default")
public SessionFactory sessionFactoryBean(DataSource dataSource) {
    try {
        LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
        lsfb.setDataSource(dataSource);
        lsfb.setPackagesToScan("com.opteral.springsms.model");
        Properties props = new Properties();
        props.setProperty("dialect", "org.hibernate.dialect.MySQLDialect");
        lsfb.setHibernateProperties(props);
        lsfb.afterPropertiesSet();
        SessionFactory object = lsfb.getObject();
        return object;
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:amalio,项目名称:spring-json-sms-gateway,代码行数:18,代码来源:DataConfig.java

示例6: buildSessionFactoryBeanDefinition

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
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;
}
 
开发者ID:xiaolongzuo,项目名称:zxl,代码行数:23,代码来源:MulCommonBaseServiceParser.java

示例7: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
/**
 * 
 * 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;
}
 
开发者ID:DevOpsDistilled,项目名称:OpERP,代码行数:23,代码来源:DbTestContext.java

示例8: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource());
        sessionFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
        Properties hibernateProperties = new Properties();
        hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
        hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
//        hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
        sessionFactoryBean.setHibernateProperties(hibernateProperties);

        return sessionFactoryBean;
    }
 
开发者ID:aollio,项目名称:school-express-delivery,代码行数:14,代码来源:ServerDataSourceConfig.java

示例9: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource());
    sessionFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
    Properties hibernateProperties = new Properties();
    hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
    hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
    hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
    sessionFactoryBean.setHibernateProperties(hibernateProperties);

    return sessionFactoryBean;
}
 
开发者ID:aollio,项目名称:school-express-delivery,代码行数:14,代码来源:DataSourceConfig.java

示例10: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
public LocalSessionFactoryBean sessionFactory(){
    LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource());
    sessionFactoryBean.setPackagesToScan(environment.getProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    sessionFactoryBean.setHibernateProperties(hibProperties());
    sessionFactoryBean.setEntityInterceptor(preInsertUpdateInterceptor());
    return sessionFactoryBean;
}
 
开发者ID:Witerium,项目名称:stuffEngine,代码行数:10,代码来源:DAOConfig.java

示例11: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
/**
 * enable @Bean annotation if you want to use hibernate instead of spring data JPA repositories
 *
 * @param dataSource
 * @return LocalSessionFactoryBean
 */
// @Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
    final LocalSessionFactoryBean sfb = new LocalSessionFactoryBean();
    sfb.setDataSource(dataSource);
    sfb.setPackagesToScan(new String[] { "com.tvajjala.persistence.domain" });
    final Properties props = new Properties();
    props.setProperty("dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
    sfb.setHibernateProperties(props);
    return sfb;
}
 
开发者ID:tvajjala,项目名称:interview-preparation,代码行数:17,代码来源:DBConfig.java

示例12: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource());
    sessionFactoryBean.setPackagesToScan("com.espark.adarsh");
    Properties hibernateProperties = new Properties();
    hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
    hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
    hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
    sessionFactoryBean.setHibernateProperties(hibernateProperties);

    return sessionFactoryBean;
}
 
开发者ID:adarshkumarsingh83,项目名称:spring_boot,代码行数:14,代码来源:PersistenceConfigurations.java

示例13: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    localSessionFactoryBean.setDataSource(dataSource);
    localSessionFactoryBean.setPackagesToScan(PACKAGES_TO_SCAN);
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.dialect", this.dialect);
    hibernateProperties.setProperty("hibernate.show_sql", Boolean.TRUE.toString());
    localSessionFactoryBean.setHibernateProperties(hibernateProperties);
    return localSessionFactoryBean;
}
 
开发者ID:belchan,项目名称:imageboard,代码行数:12,代码来源:Config.java

示例14: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@DependsOn("createFunctionInitializer")
@Bean
public LocalSessionFactoryBean sessionFactory(final DataSource dataSource) {
    final LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.setHibernateProperties(hibernateProperties());
    sessionFactoryBean.setPackagesToScan(hibernatePackagesToScan());
    Optional<String> schemaName = SingularProperties.getOpt(CUSTOM_SCHEMA_NAME);
    if (schemaName.isPresent()) {
        sessionFactoryBean.setEntityInterceptor(new SingularEntityInterceptor());
        getLogger().info("Utilizando schema customizado: {}", schemaName.get());
    }
    return sessionFactoryBean;
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:15,代码来源:SingularDefaultPersistenceConfiguration.java

示例15: sessionFactory

import org.springframework.orm.hibernate4.LocalSessionFactoryBean; //导入依赖的package包/类
@Bean
public LocalSessionFactoryBean sessionFactory() {
	LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
	sessionFactoryBean.setDataSource(dataSource());
	sessionFactoryBean.setPackagesToScan("com.servinglynk.hmis.warehouse.model");
	sessionFactoryBean.setHibernateProperties(hibProperties());
	return sessionFactoryBean;
}
 
开发者ID:hserv,项目名称:coordinated-entry,代码行数:9,代码来源:DatabaseConfig.java


注:本文中的org.springframework.orm.hibernate4.LocalSessionFactoryBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。