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


Java Configuration.addAnnotatedClass方法代碼示例

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


在下文中一共展示了Configuration.addAnnotatedClass方法的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: 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

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

示例4: HibernateHelper

import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
public HibernateHelper(Logger log, String dialect, String driver_class, String url, String username, String password, long retry, Class<?>... annotatedClasses) throws EngineException {
	this.log = log;
	this.retry = retry + 1;
	
	Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
	Element elt = doc.createElement("session-factory");
	addProperty(elt, "hibernate.connection.driver_class", driver_class);
	addProperty(elt, "hibernate.connection.url", url);
	addProperty(elt, "hibernate.connection.username", username);
	addProperty(elt, "hibernate.connection.password", password);
	addProperty(elt, "hibernate.dialect", dialect);
	addProperty(elt, "hibernate.hbm2ddl.auto", "update");
	addProperty(elt, "hibernate.connection.autocommit", "true");
	addProperty(elt, "hibernate.jdbc.batch_size", "1");
	addProperty(elt, "hibernate.show_sql", "true");
	doc.appendChild(doc.createElement("hibernate-configuration")).appendChild(elt);
	
	configuration = new Configuration();
	for (Class<?> annotatedClass: annotatedClasses) {
		configuration.addAnnotatedClass(annotatedClass);
	}
	configuration.configure(doc);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:24,代碼來源:HibernateHelper.java

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

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

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

示例8: DBServiceImpl

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

    configuration.addAnnotatedClass(UserDataSet.class);
    configuration.addAnnotatedClass(PhoneDataSet.class);
    configuration.addAnnotatedClass(EmptyDataSet.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_10,代碼行數:20,代碼來源:DBServiceImpl.java

示例9: postProcessMappings

import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
/**
 * Reads metadata from annotated classes and packages into the
 * AnnotationConfiguration instance.
 */
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
	if (this.annotatedClasses != null) {
		for (Class<?> annotatedClass : this.annotatedClasses) {
			config.addAnnotatedClass(annotatedClass);
		}
	}
	if (this.annotatedPackages != null) {
		for (String annotatedPackage : this.annotatedPackages) {
			config.addPackage(annotatedPackage);
		}
	}
	scanPackages(config);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:AnnotationSessionFactoryBean.java

示例10: registerEntityTypes

import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
private static void registerEntityTypes(Configuration config)
{
	Reflections reflections = new Reflections("pl.mmorpg.prototype.server.database.entities");
	Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Table.class);
	for (Class<?> type : entityTypes)
		config = config.addAnnotatedClass(type);
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:8,代碼來源:HibernateUtil.java

示例11: 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);
    }
    configuration.setProperties(properties);
    return configuration.buildSessionFactory(
            new BootstrapServiceRegistryBuilder()
                    .build()
    );
}
 
開發者ID:vladmihalcea,項目名稱:hibernate-types,代碼行數:29,代碼來源:AbstractTest.java

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

示例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: 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(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);
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type);
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
開發者ID:vladmihalcea,項目名稱:hibernate-types,代碼行數:47,代碼來源:AbstractTest.java


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