Search in sources :

Example 91 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class ExtendsTest method testEntityNamesWithPackage.

@Test
public void testEntityNamesWithPackage() {
    Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/packageentitynames.hbm.xml").buildMetadata();
    assertNotNull(metadata.getEntityBinding("EntityHasName"));
    assertNotNull(metadata.getEntityBinding("EntityCompany"));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 92 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class CallbackTest method prepareBootstrapRegistryBuilder.

@Override
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
    super.prepareBootstrapRegistryBuilder(builder);
    builder.applyIntegrator(new Integrator() {

        @Override
        public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
            integrate(serviceRegistry);
        }

        private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
            serviceRegistry.getService(EventListenerRegistry.class).setListeners(EventType.DELETE, listener);
            listener.initialize();
        }

        @Override
        public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
            listener.cleanup();
        }
    });
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) Integrator(org.hibernate.integrator.spi.Integrator) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry)

Example 93 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class GetAndIsVariantGetterTest method testAnnotationsCorrected.

@Test
@TestForIssue(jiraKey = "HHH-10242")
public void testAnnotationsCorrected() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity2.class).buildMetadata();
    assertNotNull(metadata.getEntityBinding(TheEntity2.class.getName()).getIdentifier());
    assertNotNull(metadata.getEntityBinding(TheEntity2.class.getName()).getIdentifierProperty());
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 94 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class DiscriminatorOptionsTest method testNonDefaultOptions.

@Test
public void testNonDefaultOptions() throws Exception {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass.class).addAnnotatedClass(SubClass.class).buildMetadata();
        PersistentClass persistentClass = metadata.getEntityBinding(BaseClass.class.getName());
        assertNotNull(persistentClass);
        assertTrue(persistentClass instanceof RootClass);
        RootClass root = (RootClass) persistentClass;
        assertTrue("Discriminator should be forced", root.isForceDiscriminator());
        assertFalse("Discriminator should not be insertable", root.isDiscriminatorInsertable());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 95 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class DiscriminatorOptionsTest method testBaseline.

@Test
public void testBaseline() throws Exception {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass2.class).addAnnotatedClass(SubClass2.class).buildMetadata();
        PersistentClass persistentClass = metadata.getEntityBinding(BaseClass2.class.getName());
        assertNotNull(persistentClass);
        assertTrue(persistentClass instanceof RootClass);
        RootClass root = (RootClass) persistentClass;
        assertFalse("Discriminator should not be forced by default", root.isForceDiscriminator());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Aggregations

Metadata (org.hibernate.boot.Metadata)148 MetadataSources (org.hibernate.boot.MetadataSources)124 Test (org.junit.Test)103 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)73 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)56 PersistentClass (org.hibernate.mapping.PersistentClass)46 TestForIssue (org.hibernate.testing.TestForIssue)31 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)18 Session (org.hibernate.Session)14 HashMap (java.util.HashMap)13 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)13 Property (org.hibernate.mapping.Property)12 RootClass (org.hibernate.mapping.RootClass)12 Map (java.util.Map)11 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 SessionFactory (org.hibernate.SessionFactory)10 Collection (org.hibernate.mapping.Collection)10 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)10 ServiceRegistry (org.hibernate.service.ServiceRegistry)8 Before (org.junit.Before)8