Search in sources :

Example 46 with Metadata

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

the class SynchronizeTableNamingTest method testAnnotationHandling.

@Test
public void testAnnotationHandling() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(DynamicEntity.class).getMetadataBuilder().applyPhysicalNamingStrategy(TestingPhysicalNamingStrategy.INSTANCE).build();
    verify(metadata.getEntityBinding(DynamicEntity.class.getName()));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 47 with Metadata

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

the class SimpleNationalizedTest method simpleNationalizedTest.

@Test
public void simpleNationalizedTest() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources ms = new MetadataSources(ssr);
        ms.addAnnotatedClass(NationalizedEntity.class);
        final Metadata metadata = ms.buildMetadata();
        PersistentClass pc = metadata.getEntityBinding(NationalizedEntity.class.getName());
        assertNotNull(pc);
        Property prop = pc.getProperty("nvarcharAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(StringType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("materializedNclobAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(MaterializedClobType.INSTANCE, prop.getType());
        } else {
            assertSame(MaterializedNClobType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("nclobAtt");
        assertSame(NClobType.INSTANCE, prop.getType());
        prop = pc.getProperty("nlongvarcharcharAtt");
        assertSame(NTextType.INSTANCE, prop.getType());
        prop = pc.getProperty("ncharArrAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterArrayType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("ncharacterAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterType.INSTANCE, prop.getType());
        } else {
            assertSame(CharacterNCharType.INSTANCE, prop.getType());
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Test(org.junit.Test)

Example 48 with Metadata

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

the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingJpaCompliantStrategy.

@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingJpaCompliantStrategy() {
    // Even in 4.3, with JPA compliant naming, Hibernate creates an unusable table...
    final MetadataSources metadataSources = new MetadataSources();
    try {
        metadataSources.addAnnotatedClass(Input.class);
        metadataSources.addAnnotatedClass(Ptx.class);
        final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
        assertSameTableUsed(metadata);
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 49 with Metadata

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

the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyJpaStrategy.

@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyJpaStrategy() {
    final MetadataSources metadataSources = new MetadataSources();
    try {
        metadataSources.addAnnotatedClass(Input.class);
        metadataSources.addAnnotatedClass(Ptx.class);
        final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE).build();
        assertSameTableUsed(metadata);
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 50 with Metadata

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

the class BaseNamingTests method doTest.

@Test
public void doTest() {
    final MetadataSources metadataSources = new MetadataSources();
    try {
        applySources(metadataSources);
        final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(getImplicitNamingStrategyToUse()).build();
        validateCustomer(metadata);
        validateOrder(metadata);
        validateZipCode(metadata);
        validateCustomerRegisteredTrademarks(metadata);
        validateCustomerAddresses(metadata);
        validateCustomerOrders(metadata);
        validateCustomerIndustries(metadata);
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) 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