Search in sources :

Example 46 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_MetadataSources_example.

@Test
public void test_bootstrap_bootstrap_native_registry_MetadataSources_example() {
    try {
        // tag::bootstrap-bootstrap-native-registry-MetadataSources-example[]
        ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
        MetadataSources sources = new MetadataSources(standardRegistry);
        // alternatively, we can build the MetadataSources without passing
        // a service registry, in which case it will build a default
        // BootstrapServiceRegistry to use.  But the approach shown
        // above is preferred
        // MetadataSources sources = new MetadataSources();
        // add a class using JPA/Hibernate annotations for mapping
        sources.addAnnotatedClass(MyEntity.class);
        // add the name of a class using JPA/Hibernate annotations for mapping.
        // differs from above in that accessing the Class is deferred which is
        // important if using runtime bytecode-enhancement
        sources.addAnnotatedClassName("org.hibernate.example.Customer");
        // Read package-level metadata.
        sources.addPackage("hibernate.example");
        // Read package-level metadata.
        sources.addPackage(MyEntity.class.getPackage());
        // Adds the named hbm.xml resource as a source: which performs the
        // classpath lookup and parses the XML
        sources.addResource("org/hibernate/example/Order.hbm.xml");
        // Adds the named JPA orm.xml resource as a source: which performs the
        // classpath lookup and parses the XML
        sources.addResource("org/hibernate/example/Product.orm.xml");
        // Read all mapping documents from a directory tree.
        // Assumes that any file named *.hbm.xml is a mapping document.
        sources.addDirectory(new File("."));
        // Read mappings from a particular XML file
        sources.addFile(new File("./mapping.xml"));
        // Read all mappings from a jar file.
        // Assumes that any file named *.hbm.xml is a mapping document.
        sources.addJar(new File("./entities.jar"));
        // Read a mapping as an application resource using the convention that a class named foo.bar.MyEntity is
        // mapped by a file named foo/bar/MyEntity.hbm.xml which can be resolved as a classpath resource.
        sources.addClass(MyEntity.class);
    // end::bootstrap-bootstrap-native-registry-MetadataSources-example[]
    } catch (Exception ignore) {
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) File(java.io.File) Test(org.junit.Test)

Example 47 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2.

@Test
public void test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2() {
    // tag::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
    // An example using an explicitly built BootstrapServiceRegistry
    BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder().build();
    StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapRegistry);
// end::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Aggregations

BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)47 Test (org.junit.Test)33 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)31 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)30 MetadataSources (org.hibernate.boot.MetadataSources)28 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)21 ServiceRegistry (org.hibernate.service.ServiceRegistry)15 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 SeContainer (javax.enterprise.inject.se.SeContainer)8 SeContainerInitializer (javax.enterprise.inject.se.SeContainerInitializer)6 Metadata (org.hibernate.boot.Metadata)5 TheEntity (org.hibernate.test.cdi.events.TheEntity)5 Properties (java.util.Properties)4 MappingException (org.hibernate.MappingException)4 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)4 TestForIssue (org.hibernate.testing.TestForIssue)4 FileInputStream (java.io.FileInputStream)3 AnnotationException (org.hibernate.AnnotationException)3 RegionFactory (org.hibernate.cache.spi.RegionFactory)3 Configuration (org.hibernate.cfg.Configuration)3