本文整理匯總了Java中org.hibernate.cfg.Configuration.buildSessionFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.buildSessionFactory方法的具體用法?Java Configuration.buildSessionFactory怎麽用?Java Configuration.buildSessionFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.buildSessionFactory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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
示例2: 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());
}
示例3: initialize
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
private static void initialize()
{
try
{
Configuration config = createConfig();
sessionFactory = config.buildSessionFactory();
} catch (Throwable ex)
{
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
示例4: 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);
}
}
示例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: main
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
public static void main(String[] args) {
String path = "hibernate.cfg.xml";
Configuration cfg = new Configuration().configure(path);
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
User user = new User();
user.setId("46");
user.setName("aaa");
session.save(user);
// session.close();
session.getTransaction().commit();
sessionFactory.close();
}
示例7: configureSessionFactory
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
private static SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
Properties properties = configuration.getProperties();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
applySettings(properties).buildServiceRegistry();
SessionFactory sessionFactory = configuration.
buildSessionFactory(serviceRegistry);
return sessionFactory;
}
示例8: main
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
public static void main(String[] args) {
Configuration cfg=null;
SessionFactory sf=null;
Session ses=null;
//activate the hibernate framework
cfg=new Configuration().configure("hibernate.cfg.xml");
//build the session factory
sf=cfg.buildSessionFactory();
//open/get the session
ses=sf.openSession();
//create the model class object and set the data
Employee e=new Employee();
//create then sql query
String sql="SELECT * FROM EMP_NATIVE";
SQLQuery q=ses.createSQLQuery(sql);
q.addEntity(Employee.class);
//execute the query
List<Employee> emplist=q.list();
//display the data
emplist.forEach(row->{
System.out.println("\t"+row.getId()+"\t"+row.getName()+"\t"+row.getSal());
});
//close the session factory and session
ses.close();
sf.close();
}
示例9: rebuildSessionFactory
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
public static void rebuildSessionFactory(){
try {
//讀取配置信息
Configuration configuration= new Configuration().configure();
sessionFactory=configuration.buildSessionFactory();//創建sessionFactory
} catch (Exception e) {
System.out.println("Error creating sessionFactory!");
e.printStackTrace();
}
}
示例10: init
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
@Before
public void init() {
// 準備環境
{
Configuration configuration = new Configuration().configure("hbm.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
factory = configuration.buildSessionFactory(serviceRegistry);
}
}
示例11: SessionFactory
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
private SessionFactory() {
try {
HibernateConfiguration hibernateConfiguration = ConfigurationWrapper.getInstance().getHibernateConfiguration();
Configuration configuration = new Configuration();
initHBMs(configuration);
configuration.configure(hibernateConfiguration.getPathToConfigurationFile());
StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(standardServiceRegistryBuilder.build());
}catch (Exception excetption){
}
}
示例12: createSessionFactory
import org.hibernate.cfg.Configuration; //導入方法依賴的package包/類
private static SessionFactory createSessionFactory(Configuration configuration) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例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: 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);
}