本文整理汇总了Java中org.hibernate.cfg.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于org.hibernate.cfg包,在下文中一共展示了Configuration类的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: 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();
String hql="select item_name from bigbazarModel where bazarid=:id";
Query q=ses.createQuery(hql);
q.setParameter("id", 1001);
String s=(String) q.uniqueResult();
System.out.println("\t\t"+s);
factory.close();
}
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:19,代码来源:TestClass.java
示例3: 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
示例4: 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());
}
示例5: 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);
}
示例6: 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);
}
示例7: init
import org.hibernate.cfg.Configuration; //导入依赖的package包/类
@PostConstruct
public void init() throws ClassNotFoundException
{
final Configuration configuration = annotationSessionFactory
.getConfiguration();
final ReflectionManager reflectionManager = configuration
.getReflectionManager();
final Iterator<PersistentClass> classMappings = configuration
.getClassMappings();
while (classMappings.hasNext())
{
entityCallbackHandler.add(reflectionManager.classForName(
classMappings.next().getClassName(), this.getClass()),
reflectionManager);
}
}
示例8: 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);
}
示例9: 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);
}
}
示例10: createConnection
import org.hibernate.cfg.Configuration; //导入依赖的package包/类
public static synchronized void createConnection() {
try {
if (sessionFactory == null) {
sessionFactory = new Configuration().configure("com/coder/hms/connection/hibernate.cfg.xml")
.addAnnotatedClass(Reservation.class).buildSessionFactory();
}
} catch (HibernateException e) {
Toolkit.getDefaultToolkit().beep();
final InformationFrame dialog = new InformationFrame();
dialog.setMessage("Sorry we can't connect to database right now, without "
+ "connection the application will not work properly.");
dialog.okBtn.addActionListener(ActionListener->{
return;
});
dialog.setVisible(true);
}
}
示例11: 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());
}
示例12: 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);
}
示例13: SchemaExport
import org.hibernate.cfg.Configuration; //导入依赖的package包/类
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) {
this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
serviceRegistry.getService( ConnectionProvider.class )
);
this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
configuration.getProperties(),
DEFAULT_IMPORT_FILE
);
final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
this.dropSQL = configuration.generateDropSchemaScript( dialect );
this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
示例14: getSchemaUpdate
import org.hibernate.cfg.Configuration; //导入依赖的package包/类
private SchemaUpdate getSchemaUpdate(Configuration cfg) throws HibernateException, IOException {
Properties properties = new Properties();
properties.putAll( cfg.getProperties() );
if (propertiesFile == null) {
properties.putAll( getProject().getProperties() );
}
else {
properties.load( new FileInputStream(propertiesFile) );
}
cfg.setProperties(properties);
SchemaUpdate su = new SchemaUpdate(cfg);
su.setOutputFile( outputFile.getPath() );
su.setDelimiter(delimiter);
su.setHaltOnError(haltOnError);
return su;
}
示例15: SessionFactoryServiceRegistryImpl
import org.hibernate.cfg.Configuration; //导入依赖的package包/类
@SuppressWarnings( {"unchecked"})
public SessionFactoryServiceRegistryImpl(
ServiceRegistryImplementor parent,
SessionFactoryImplementor sessionFactory,
Configuration configuration) {
super( parent );
this.sessionFactory = sessionFactory;
this.configuration = configuration;
this.metadata = null;
// for now, just use the standard initiator list
for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
// create the bindings up front to help identify to which registry services belong
createServiceBinding( initiator );
}
}