Example usage for org.hibernate.boot MetadataSources MetadataSources

List of usage examples for org.hibernate.boot MetadataSources MetadataSources

Introduction

In this page you can find the example usage for org.hibernate.boot MetadataSources MetadataSources.

Prototype

public MetadataSources(ServiceRegistry serviceRegistry) 

Source Link

Document

Create a metadata sources using the specified service registry.

Usage

From source file:SessionFactoryBuilder.java

protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
            .build();//from w  ww .  ja v a  2 s.c  om
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}

From source file:TeachingPlanMandatoryTest.java

License:Open Source License

@Override
protected void setUp() throws Exception {

    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
    try {/*from  ww w.  j a  va2 s .com*/
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {

        StandardServiceRegistryBuilder.destroy(registry);
    }
}

From source file:basedistribuida.connection.Connection.java

public static SessionFactory getSessionFactory() {
    final ServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
    return new MetadataSources(registry).buildMetadata().buildSessionFactory();
}

From source file:basedistribuida.connection.Connection.java

public static SessionFactory getSessionFactory(String config) throws Exception {
    final ServiceRegistry registry = new StandardServiceRegistryBuilder().configure(config).build();
    return new MetadataSources(registry).buildMetadata().buildSessionFactory();
}

From source file:bd.ac.seu.contactapp.util.HibernateUtil.java

private HibernateUtil() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
            .build();//from  w ww . ja va2s.  co  m
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:bd.ac.seu.hibernatedemo.util.SessionFactorySingleton.java

private SessionFactorySingleton() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
            .build();//w w w  .  j a v  a2 s.c o m
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:bd.ac.seu.my.hibernatespringdemo.utill.SessionFactorySingleton.java

private SessionFactorySingleton() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
            .build();/*from   w  w  w. j a va2  s.co m*/
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.uece.goes.model.ObjectDAO.java

protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
            .build();/* www. ja v  a  2s . c  o m*/
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        e.printStackTrace();
        StandardServiceRegistryBuilder.destroy(registry);
    }
}

From source file:com.abcanthur.website.codegenhack.JPADatabase.java

License:Apache License

@SuppressWarnings("serial")
@Override//from  w w w .  ja va2 s.  co  m
protected DSLContext create0() {
    if (connection == null) {
        String packages = getProperties().getProperty("packages");

        if (isBlank(packages)) {
            packages = "";
            log.warn("No packages defined",
                    "It is highly recommended that you provide explicit packages to scan");
        }

        try {
            connection = DriverManager.getConnection("jdbc:h2:mem:jooq-meta-extensions", "sa", "");

            MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder()
                    .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
                    .applySetting("javax.persistence.schema-generation-connection", connection)

                    // [#5607] JPADatabase causes warnings - This prevents them
                    .applySetting(AvailableSettings.CONNECTION_PROVIDER,
                            "com.abcanthur.website.codegenhack.CustomConnectionProvider")
                    .build());

            ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
                    true);

            scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
            for (String pkg : packages.split(","))
                for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim()))
                    metadata.addAnnotatedClass(Class.forName(def.getBeanClassName()));

            // This seems to be the way to do this in idiomatic Hibernate 5.0 API
            // See also: http://stackoverflow.com/q/32178041/521799
            // SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
            // export.create(true, true);

            // Hibernate 5.2 broke 5.0 API again. Here's how to do this now:
            SchemaExport export = new SchemaExport();
            export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
        } catch (Exception e) {
            throw new DataAccessException("Error while exporting schema", e);
        }
    }

    return DSL.using(connection);
}

From source file:com.archolding.util.ConnectionHelper.java

public static void setUp() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();

    try {/*ww w .  ja  v a2  s  . c  om*/
        sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}