本文整理汇总了Java中org.hibernate.cfg.Configuration.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setProperty方法的具体用法?Java Configuration.setProperty怎么用?Java Configuration.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.setProperty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static SessionFactory getSessionFactory() {
if (null != sessionFactory)
return sessionFactory;
Configuration configuration = new Configuration();
String jdbcUrl = "jdbc:mysql://"
+ System.getenv("RDS_HOSTNAME")
+ "/"
+ System.getenv("RDS_DB_NAME");
configuration.setProperty("hibernate.connection.url", jdbcUrl);
configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (HibernateException e) {
System.err.println("Initial SessionFactory creation failed." + e);
throw new ExceptionInInitializerError(e);
}
return sessionFactory;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例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());
}
示例6: 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());
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: changeDialect
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
/**
* Substitute the dialect with an alternative, if possible.
*
* @param cfg
* the configuration
* @param dialect
* the dialect
* @return the dialect
*/
private Dialect changeDialect(Configuration cfg, Dialect dialect)
{
String dialectName = cfg.getProperty(Environment.DIALECT);
if (dialectName == null || dialectName.length() == 0)
{
// Fix the dialect property to match the detected dialect
cfg.setProperty(Environment.DIALECT, dialect.getClass().getName());
}
return dialect;
// TODO: https://issues.alfresco.com/jira/browse/ETHREEOH-679
// else if (dialectName.equals(Oracle9Dialect.class.getName()))
// {
// String subst = AlfrescoOracle9Dialect.class.getName();
// LogUtil.warn(logger, WARN_DIALECT_SUBSTITUTING, dialectName, subst);
// cfg.setProperty(Environment.DIALECT, subst);
// }
// else if (dialectName.equals(MySQLDialect.class.getName()))
// {
// String subst = MySQLInnoDBDialect.class.getName();
// LogUtil.warn(logger, WARN_DIALECT_SUBSTITUTING, dialectName, subst);
// cfg.setProperty(Environment.DIALECT, subst);
// }
// else if (dialectName.equals(MySQL5Dialect.class.getName()))
// {
// String subst = MySQLInnoDBDialect.class.getName();
// LogUtil.warn(logger, WARN_DIALECT_SUBSTITUTING, dialectName, subst);
// cfg.setProperty(Environment.DIALECT, subst);
// }
}