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


Java Metadata.buildSessionFactory方法代码示例

本文整理汇总了Java中org.hibernate.boot.Metadata.buildSessionFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Metadata.buildSessionFactory方法的具体用法?Java Metadata.buildSessionFactory怎么用?Java Metadata.buildSessionFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.boot.Metadata的用法示例。


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

示例1: start

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@Override
public void start() {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url)
            .applySetting("hibernate.dialect", config.persistence.dialect)
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            .build();

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:27,代码来源:HibernatePersistenceProvider.java

示例2: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@Before
public void setup() {
	StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
		.applySetting( "hibernate.show_sql", "true" )
		.applySetting( "hibernate.format_sql", "true" )
		.applySetting( "hibernate.hbm2ddl.auto", "update" )
		.applySetting( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
		.applySetting( "hibernate.connection.driver_class", "org.h2.Driver" )
		.applySetting( "hibernate.connection.url", "jdbc:h2:mem:testdbHibernate" )
		.applySetting( "hibernate.connection.username", "sa" )
		.applySetting( "hibernate.connection.password", "" )
		.applySetting( "hibernate.use_sql_comment", "true" )
		;
	Metadata metadata  = null;
	if(packageBase()== null){
	metadata= new MetadataSources( srb.build() ).addAnnotatedClass(getEntityClass()).buildMetadata();
	}else{
	    metadata= new MetadataSources( srb.build() )
	            .addAnnotatedClass(Item.class)
	            .addAnnotatedClass(Offer.class)

	            .addPackage(packageBase()).buildMetadata();
	}

       sf = metadata.buildSessionFactory();
   }
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:27,代码来源:ORMStandaloneTestCase.java

示例3: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
    // @formatter:off
    StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.show_sql", "true")
            .applySetting("hibernate.format_sql", "true")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("use_sql_comments", "true")
            .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
            .applySetting("hibernate.connection.driver_class", "org.h2.Driver")
            .applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
            .applySetting("hibernate.connection.username", "sa")
            .applySetting("hibernate.connection.password", "")
            .applySetting("hibernate.use_sql_comment", "true");
    Metadata metadata = null;
    log.info("+++ setup");
    metadata = new MetadataSources(srb.build()).addAnnotatedClass(EmailMessage.class).addAnnotatedClass(Email.class).buildMetadata();

    sf = metadata.buildSessionFactory();
    // @formatter:on
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:22,代码来源:ORMStandaloneClassTestCase.java

示例4: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
    // @formatter:off
    StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.show_sql", "true")
            .applySetting("hibernate.format_sql", "true")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("use_sql_comments", "true")
            .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
            .applySetting("hibernate.connection.driver_class", "org.h2.Driver")
            .applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
            .applySetting("hibernate.connection.username", "sa")
            .applySetting("hibernate.connection.password", "")
            .applySetting("hibernate.use_sql_comment", "true");
    Metadata metadata = null;
    log.info("+++ setup");
    metadata = new MetadataSources(srb.build()).addAnnotatedClass(Address.class).addAnnotatedClass(User.class).buildMetadata();

    sf = metadata.buildSessionFactory();
    // @formatter:on
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:22,代码来源:ORMStandaloneClassTestCase.java

示例5: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
    StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder().applySetting("hibernate.show_sql", "true").applySetting("hibernate.format_sql", "true").applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").applySetting("hibernate.connection.driver_class", "org.h2.Driver")
            .applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate").applySetting("hibernate.connection.username", "sa").applySetting("hibernate.connection.password", "")
            .applySetting("hibernate.use_sql_comment", "true");
    Metadata metadata = null;
    log.info("+++ setup");
    metadata = new MetadataSources(srb.build()).addAnnotatedClass(Book.class).buildMetadata();

    sf = metadata.buildSessionFactory();
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:13,代码来源:ORMStandaloneClassTestCase.java

示例6: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@Before
public void setup() {
	StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
		.applySetting( "hibernate.show_sql", "true" )
		.applySetting( "hibernate.format_sql", "true" )
		.applySetting( "hibernate.hbm2ddl.auto", "update" )
		.applySetting( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
		.applySetting( "hibernate.connection.driver_class", "org.h2.Driver" )
		.applySetting( "hibernate.connection.url", "jdbc:h2:mem:testdbHibernate" )
		.applySetting( "hibernate.connection.username", "sa" )
		.applySetting( "hibernate.connection.password", "" )
		.applySetting( "hibernate.use_sql_comment", "true" )
		;
	Metadata metadata  = null;
	if(packageBase()== null){
	metadata= new MetadataSources( srb.build() ).addAnnotatedClass(getEntityClass()).buildMetadata();
	}else{
	    metadata= new MetadataSources( srb.build() )
	            .addAnnotatedClass(Item.class)
	            .addAnnotatedClass(Tank.class)
	            .addAnnotatedClass(Crew.class)
	            .addAnnotatedClass(TankBi.class)
	            .addAnnotatedClass(CrewBi.class)
	            .addPackage(packageBase()).buildMetadata();
	}

       sf = metadata.buildSessionFactory();
   }
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:29,代码来源:ORMStandaloneTestCase.java

示例7: setup

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@Before
public void setup() {
	StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
		.applySetting( "hibernate.show_sql", "true" )
		.applySetting( "hibernate.format_sql", "true" )
		.applySetting( "hibernate.hbm2ddl.auto", "update" )
		.applySetting( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
		.applySetting( "hibernate.connection.driver_class", "org.h2.Driver" )
		.applySetting( "hibernate.connection.url", "jdbc:h2:mem:testdbHibernate" )
		.applySetting( "hibernate.connection.username", "sa" )
		.applySetting( "hibernate.connection.password", "" )
		.applySetting( "hibernate.use_sql_comment", "true" )
		;
	Metadata metadata  = null;
	if(packageBase()== null){
	metadata= new MetadataSources( srb.build() ).addAnnotatedClass(getEntityClass()).buildMetadata();
	}else{
	    metadata= new MetadataSources( srb.build() )
	            .addAnnotatedClass(Product.class)
	            .addAnnotatedClass(ProductCustomer.class)
	            .addAnnotatedClass(ProductResource.class)
	            .addAnnotatedClass(Part.class)

	            .addPackage(packageBase()).buildMetadata();
	}

       sf = metadata.buildSessionFactory();
   }
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:29,代码来源:ORMStandaloneMany2OneTestCase.java

示例8: startHibernate

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
    builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}
 
开发者ID:apache,项目名称:ignite,代码行数:36,代码来源:HibernateL2CacheStrategySelfTest.java

示例9: startHibernate

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = registryBuilder();

    for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    // Use the same cache for Entity and Entity2.
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    StandardServiceRegistry srvcRegistry = builder.build();

    MetadataSources metadataSources = new MetadataSources(srvcRegistry);

    for (Class entityClass : getAnnotatedClasses())
        metadataSources.addAnnotatedClass(entityClass);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
        collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() );

    return metadata.buildSessionFactory();
}
 
开发者ID:apache,项目名称:ignite,代码行数:36,代码来源:HibernateL2CacheSelfTest.java

示例10: start

import org.hibernate.boot.Metadata; //导入方法依赖的package包/类
@Override
public void start() {
    // don't judge me, bukkit doesn't want to resolve those so we need to manually load them
    Class[] iDontEvenKnow = new Class[]{CoreMessageLogger_$logger.class, Log_$logger.class,
            ConnectionPoolingLogger_$logger.class, EntityManagerMessageLogger_$logger.class, ConnectionAccessLogger_$logger.class};

    boolean shouldCreateTable = config.persistence.initialTableCreation;
    if (shouldCreateTable) {
        config.persistence.initialTableCreation = false;
        configHandler.saveGlobalConfig();
    }

    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            // credentials and stuff
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url + "?useSSL=false")
            .applySetting("hibernate.dialect", config.persistence.dialect)
            // misc settings
            .applySetting("hibernate.hbm2ddl.auto", shouldCreateTable ? "create" : "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            //TODO apparently this is an anti-pattern [0], but it fixes an issue so ¯\_(ツ)_/¯
            // [0]: https://vladmihalcea.com/2016/09/05/the-hibernate-enable_lazy_load_no_trans-anti-pattern/
            .applySetting("hibernate.enable_lazy_load_no_trans", true)
            .applySetting("hibernate.connection.autocommit", true)
            // connection pool
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            //TODO figure out how to use hikari with hibernate
            //.applySetting("hibernate.connection.provider_class","com.zaxxer.hikari.hibernate.HikariConnectionProvider")
            .build();

    JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(ComponentTypeDescriptor.INSTANCE);

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections("").getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:48,代码来源:HibernatePersistenceProvider.java


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