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