Example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder configure

List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder configure

Introduction

In this page you can find the example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder configure.

Prototype

public StandardServiceRegistryBuilder configure() 

Source Link

Document

Read setting information from an XML file using the standard resource location.

Usage

From source file:com.imos.sample.service.HibernateService.java

/**
 * Hibernate configuration.//  w ww .j a  va  2s  . c  o  m
 *
 * @throws RepositoryException
 */
public void config() throws RepositoryException {
    try {
        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
        if (filePath == null || filePath.isEmpty()) {
            registryBuilder = registryBuilder.configure();
        } else {
            registryBuilder = registryBuilder.configure(filePath);
        }
        registry = registryBuilder.build();

        MetadataSources metaData = new MetadataSources(registry);
        sessionFactory = metaData.buildMetadata().buildSessionFactory();
        session = sessionFactory.openSession();

        SchemaExport schemaExport = new SchemaExport();
        schemaExport.setDelimiter(";");
        schemaExport.setFormat(true);
        schemaExport.setManageNamespaces(true);
        schemaExport.setOutputFile("./ddl_skilldb.sql");
        schemaExport.execute(EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE, TargetType.STDOUT),
                SchemaExport.Action.CREATE, metaData.buildMetadata(registry), registry);

        log.info("Configuration succeed");
    } catch (HibernateException e) {
        StandardServiceRegistryBuilder.destroy(registry);
        log.error("Configuration failed : {}", e);
    }
}

From source file:org.glite.security.voms.admin.persistence.deployer.SchemaDeployer.java

License:Apache License

private MetadataSources getHibernateMetadataSources() {

    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();

    if (hibernatePropertiesFile == null) {
        registryBuilder.loadProperties(new File(getHibernateConfigurationFile(vo)));
    } else {/*from   w ww. j a  v a 2s  .  c o m*/
        registryBuilder.loadProperties(new File(hibernatePropertiesFile));
    }
    registryBuilder.configure();
    MetadataSources sources = new MetadataSources(registryBuilder.build());
    return sources;
}