本文整理匯總了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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()
);
}
示例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);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}