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


Java Configuration.buildSessionFactory方法代码示例

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


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

示例1: main

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	 Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		tx=ses.beginTransaction();
		 String hql="insert into newMall(mallid,item_name,item_price,item_quantity) "
		 			+ "select bazarid,item_name,item_price,item_quantity from bigbazarModel ";
		 Query q=ses.createQuery(hql);
		 			int c=q.executeUpdate();
		 			//int count=Integer.parseUnsignedInt(c);
		 			tx.commit();
		 			System.out.println("\t\t"+c+" rows Copied Successfully...");
		 		
		 			factory.close();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:22,代码来源:copy_HQL.java

示例2: createSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.driver_class",
      "io.opentracing.contrib.jdbc.TracingDriver");
  configuration.setProperty("hibernate.connection.url",
      "jdbc:tracing:h2:mem:hibernate?traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
  configuration.setProperty("hibernate.connection.username", "sa");
  configuration.setProperty("hibernate.connection.password", "");
  configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
  configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  configuration.setProperty("hibernate.show_sql", "true");
  configuration.setProperty("hibernate.connection.pool_size", "10");

  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
      .applySettings(configuration.getProperties());
  return configuration.buildSessionFactory(builder.build());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:19,代码来源:HibernateTest.java

示例3: initialize

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static void initialize()
{
	try
	{
		Configuration config = createConfig();
		sessionFactory = config.buildSessionFactory();
	} catch (Throwable ex)
	{
		System.err.println("Initial SessionFactory creation failed." + ex);
		throw new ExceptionInInitializerError(ex);
	}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:13,代码来源:HibernateUtil.java

示例4: buildSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static SessionFactory buildSessionFactory() {
	try {

		logger.info("Configurando conexao Hibernate->MySQL");
		Configuration configuration = new Configuration().configure();

		logger.info("Hibernate->MySQL - Properties: " + configuration.getProperties());

		// Create the SessionFactory from hibernate.cfg.xml
		return configuration.buildSessionFactory();

	} catch (Throwable ex) {
		// Make sure you log the exception, as it might be swallowed
		logger.error("Initial SessionFactory creation failed." + ex);
		throw new ExceptionInInitializerError(ex);
	}
}
 
开发者ID:mrh3nry,项目名称:Celebino,代码行数:18,代码来源:HibernateUtil.java

示例5: createSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
/**
 * Configuration of session factory with Fabric integration.
 */
public static SessionFactory createSessionFactory(String fabricUrl, String username, String password, String fabricUser, String fabricPassword)
        throws Exception {
    // creating this here allows passing needed params to the constructor
    FabricMultiTenantConnectionProvider connProvider = new FabricMultiTenantConnectionProvider(fabricUrl, "employees", "employees", username, password,
            fabricUser, fabricPassword);
    ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
    srb.addService(org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider.class, connProvider);
    srb.applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");

    Configuration config = new Configuration();
    config.setProperty("hibernate.multiTenancy", "DATABASE");
    config.addResource("com/mysql/fabric/demo/employee.hbm.xml");
    return config.buildSessionFactory(srb.buildServiceRegistry());
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:18,代码来源:HibernateFabric.java

示例6: main

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
    String path = "hibernate.cfg.xml";
    Configuration cfg = new Configuration().configure(path);

    SessionFactory sessionFactory = cfg.buildSessionFactory();

    Session session = sessionFactory.openSession();
    session.beginTransaction();
    User user = new User();
    user.setId("46");
    user.setName("aaa");
    session.save(user);
    // session.close();
    session.getTransaction().commit();
    sessionFactory.close();
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:17,代码来源:InHibernate.java

示例7: configureSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static SessionFactory configureSessionFactory()
        throws HibernateException {
    Configuration configuration = new Configuration();  
    configuration.configure();  

    Properties properties = configuration.getProperties();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
        applySettings(properties).buildServiceRegistry();          
    SessionFactory sessionFactory = configuration.
        buildSessionFactory(serviceRegistry);  

    return sessionFactory;  
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:15,代码来源:App.java

示例8: main

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory sf=null;
	Session ses=null;
	//activate the hibernate framework
		cfg=new Configuration().configure("hibernate.cfg.xml");
		//build the session factory
		sf=cfg.buildSessionFactory();
		//open/get the session
		ses=sf.openSession();
		
		//create the model class object and set the data
		Employee e=new Employee();
		
		//create then sql query
		
		String sql="SELECT * FROM EMP_NATIVE";
			SQLQuery q=ses.createSQLQuery(sql);
			q.addEntity(Employee.class);
	//execute the query
		List<Employee> emplist=q.list();
		//display the data
		emplist.forEach(row->{
			System.out.println("\t"+row.getId()+"\t"+row.getName()+"\t"+row.getSal());
		});
	
				//close the session factory and session
				ses.close();
				sf.close();
	
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Native_SQL_Maven_Annotation,代码行数:32,代码来源:TestClass.java

示例9: rebuildSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void rebuildSessionFactory(){
	try {
		//读取配置信息
	 Configuration configuration= new Configuration().configure();
	 sessionFactory=configuration.buildSessionFactory();//创建sessionFactory
	} catch (Exception e) {
		System.out.println("Error creating sessionFactory!");
		e.printStackTrace();
	}
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:11,代码来源:HibernateUtils.java

示例10: init

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
@Before
public void init() {

    // 准备环境
    {
        Configuration configuration = new Configuration().configure("hbm.cfg.xml");
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        factory = configuration.buildSessionFactory(serviceRegistry);
    }
}
 
开发者ID:Strangeen,项目名称:excel-util4j,代码行数:12,代码来源:TestImportHandlerForCascadePojo.java

示例11: SessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory() {
    try {
        HibernateConfiguration hibernateConfiguration = ConfigurationWrapper.getInstance().getHibernateConfiguration();
        Configuration configuration = new Configuration();
        initHBMs(configuration);
        configuration.configure(hibernateConfiguration.getPathToConfigurationFile());
        StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
        sessionFactory = configuration.buildSessionFactory(standardServiceRegistryBuilder.build());
    }catch (Exception excetption){

    }
}
 
开发者ID:Shiroukoji,项目名称:FH-Manager,代码行数:13,代码来源:SessionFactory.java

示例12: createSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static SessionFactory createSessionFactory(Configuration configuration) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:7,代码来源:DBServiceImpl.java

示例13: newLegacySessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
            additionalTypes.stream().forEach(type -> {
                if (type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType) {
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:44,代码来源:AbstractTest.java

示例14: newSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type, new String[]{type.getName()});
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type, new String[]{type.getName()});
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:47,代码来源:AbstractTest.java

示例15: DataManager

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public DataManager(Config config) throws ServerException {
	// Disable hibernate logging
	@SuppressWarnings("unused")
	org.jboss.logging.Logger logger = org.jboss.logging.Logger.getLogger("org.hibernate");
	java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.WARNING);

	// Disable c3p0 logging
	Properties p = new Properties(System.getProperties());
	p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
	p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");
	System.setProperties(p);

	Properties properties = new Properties();

	properties.setProperty("hibernate.show_sql", config.get("database.show_sql").getAsBoolean() ? "true" : "false");

	switch (config.get("database.provider").getAsString()) {
	case "mysql":
		properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL57Dialect");
		properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");

		properties.setProperty("hibernate.connection.CharSet", "utf8");
		properties.setProperty("hibernate.connection.characterEncoding", "utf8");
		properties.setProperty("hibernate.connection.useUnicode", "true");

		properties.setProperty("hibernate.connection.url", (new StringBuilder())
				.append("jdbc:mysql://")
				.append(config.get("database.mysql.host").getAsString())
				.append(":")
				.append(config.get("database.mysql.port").getAsShort())
				.append("/")
				.append(config.get("database.mysql.database").getAsString())
				.toString());

		properties.setProperty("hibernate.connection.username", config.get("database.mysql.user").getAsString());
		properties.setProperty("hibernate.connection.password", config.get("database.mysql.password").getAsString());
		break;
	default:
		throw new ServerException("Invalid data provider " + config.get("database.provider").getAsString());
	}

	Configuration configuration = new Configuration()
			.configure()
			.addProperties(properties);

	configuration.addPackage("royaleserver.database.entity");
	for (Class<?> clazz : (new Reflections("royaleserver.database.entity")).getTypesAnnotatedWith(Entity.class)) {
		if (!Modifier.isAbstract(clazz.getModifiers())) {
			configuration.addAnnotatedClass(clazz);
		}
	}

	sessionFactory = configuration.buildSessionFactory();
	services = new DataServices(sessionFactory);
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:56,代码来源:DataManager.java


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