當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration類代碼示例

本文整理匯總了Java中org.hibernate.cfg.Configuration的典型用法代碼示例。如果您正苦於以下問題:Java Configuration類的具體用法?Java Configuration怎麽用?Java Configuration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Configuration類屬於org.hibernate.cfg包,在下文中一共展示了Configuration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSessionFactory

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
private SessionFactory createSessionFactory(String options) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.url", "jdbc:p6spy:hsqldb:mem:hibernate" + options);
  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());
  SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
  return sessionFactory;
}
 
開發者ID:opentracing-contrib,項目名稱:java-p6spy,代碼行數:17,代碼來源:HibernateTest.java

示例2: 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();
	
		 String hql="select item_name from bigbazarModel where bazarid=:id";
		 Query q=ses.createQuery(hql);
		 		q.setParameter("id", 1001);
		 			String s=(String) q.uniqueResult();
		 			System.out.println("\t\t"+s);
		 			
		 			factory.close();

}
 
開發者ID:pratikdimble,項目名稱:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代碼行數:19,代碼來源:TestClass.java

示例3: 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

示例4: 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

示例5: DBServiceImpl

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public DBServiceImpl() {
    Configuration configuration = new Configuration();

    configuration.addAnnotatedClass(UserDataSet.class);
    configuration.addAnnotatedClass(PhoneDataSet.class);

    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    configuration.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db_example");
    configuration.setProperty("hibernate.connection.username", "tully");
    configuration.setProperty("hibernate.connection.password", "tully");
    configuration.setProperty("hibernate.show_sql", "true");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.connection.useSSL", "false");
    configuration.setProperty("hibernate.enable_lazy_load_no_trans", "true");
    configuration.setProperty("hibernate.jdbc.time_zone", "UTC");

    sessionFactory = createSessionFactory(configuration);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:20,代碼來源:DBServiceImpl.java

示例6: DBServiceImpl

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public DBServiceImpl() {
    Configuration configuration = new Configuration();

    configuration.addAnnotatedClass(UserDataSet.class);
    configuration.addAnnotatedClass(PhoneDataSet.class);
    configuration.addAnnotatedClass(AddressDataSet.class);

    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    configuration.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db_example");
    configuration.setProperty("hibernate.connection.username", "tully");
    configuration.setProperty("hibernate.connection.password", "tully");
    configuration.setProperty("hibernate.show_sql", "true");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.connection.useSSL", "false");
    configuration.setProperty("hibernate.enable_lazy_load_no_trans", "true");

    sessionFactory = createSessionFactory(configuration);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:20,代碼來源:DBServiceImpl.java

示例7: init

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
@PostConstruct
public void init() throws ClassNotFoundException
{
  final Configuration configuration = annotationSessionFactory
        .getConfiguration();
  final ReflectionManager reflectionManager = configuration
        .getReflectionManager();
  final Iterator<PersistentClass> classMappings = configuration
        .getClassMappings();
  while (classMappings.hasNext()) 
  {
     entityCallbackHandler.add(reflectionManager.classForName(
        classMappings.next().getClassName(), this.getClass()),
        reflectionManager);
  }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:17,代碼來源:EntityCallbackHandlerInitializer.java

示例8: DBServiceImpl

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public DBServiceImpl() {
    Configuration configuration = new Configuration();

    configuration.addAnnotatedClass(UserDataSet.class);
    configuration.addAnnotatedClass(PhoneDataSet.class);

    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    configuration.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db_example");
    configuration.setProperty("hibernate.connection.username", "tully");
    configuration.setProperty("hibernate.connection.password", "tully");
    configuration.setProperty("hibernate.show_sql", "true");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.connection.useSSL", "false");
    configuration.setProperty("hibernate.enable_lazy_load_no_trans", "true");

    sessionFactory = createSessionFactory(configuration);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:19,代碼來源:DBServiceImpl.java

示例9: 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

示例10: createConnection

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public static synchronized void createConnection() {
	try {

		if (sessionFactory == null) {
			sessionFactory = new Configuration().configure("com/coder/hms/connection/hibernate.cfg.xml")
					.addAnnotatedClass(Reservation.class).buildSessionFactory();
		}

	} catch (HibernateException e) {
		Toolkit.getDefaultToolkit().beep();
		final InformationFrame dialog = new InformationFrame();
		dialog.setMessage("Sorry we can't connect to database right now, without "
				+ "connection the application will not work properly.");
		dialog.okBtn.addActionListener(ActionListener->{
			return;
		});
		dialog.setVisible(true);
	}
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:20,代碼來源:DataSourceFactory.java

示例11: 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

示例12: DbService

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public DbService() {
    Configuration configuration = new Configuration();

    configuration.addAnnotatedClass(UserDataSet.class);
    configuration.addAnnotatedClass(AddressDataSet.class);
    configuration.addAnnotatedClass(PhoneDataSet.class);
    configuration.addAnnotatedClass(Account.class);

    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:~/test");
    configuration.setProperty("hibernate.connection.username", "sa");
    configuration.setProperty("hibernate.connection.password", "");
    configuration.setProperty("hibernate.show_sql", "true");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.connection.useSSL", "false");
    configuration.setProperty("hibernate.enable_lazy_load_no_trans", "true");

    sessionFactory = createSessionFactory(configuration);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:21,代碼來源:DbService.java

示例13: SchemaExport

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) {
	this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
			serviceRegistry.getService( ConnectionProvider.class )
	);
	this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
	this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
	this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();

	this.importFiles = ConfigurationHelper.getString(
			AvailableSettings.HBM2DDL_IMPORT_FILES,
			configuration.getProperties(),
			DEFAULT_IMPORT_FILE
	);

	final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
	this.dropSQL = configuration.generateDropSchemaScript( dialect );
	this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:SchemaExport.java

示例14: getSchemaUpdate

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
private SchemaUpdate getSchemaUpdate(Configuration cfg) throws HibernateException, IOException {
	Properties properties = new Properties();
	properties.putAll( cfg.getProperties() );
	if (propertiesFile == null) {
		properties.putAll( getProject().getProperties() );
	}
	else {
		properties.load( new FileInputStream(propertiesFile) );
	}
	cfg.setProperties(properties);
	SchemaUpdate su = new SchemaUpdate(cfg);
	su.setOutputFile( outputFile.getPath() );
	su.setDelimiter(delimiter);
	su.setHaltOnError(haltOnError);
	return su;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:SchemaUpdateTask.java

示例15: SessionFactoryServiceRegistryImpl

import org.hibernate.cfg.Configuration; //導入依賴的package包/類
@SuppressWarnings( {"unchecked"})
public SessionFactoryServiceRegistryImpl(
		ServiceRegistryImplementor parent,
		SessionFactoryImplementor sessionFactory,
		Configuration configuration) {
	super( parent );

	this.sessionFactory = sessionFactory;
	this.configuration = configuration;
	this.metadata = null;

	// for now, just use the standard initiator list
	for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
		// create the bindings up front to help identify to which registry services belong
		createServiceBinding( initiator );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:SessionFactoryServiceRegistryImpl.java


注:本文中的org.hibernate.cfg.Configuration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。