Search in sources :

Example 16 with Metadata

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

the class JoinColumnOverrideTest method testBlownPrecision.

@Test
@TestForIssue(jiraKey = "ANN-748")
public void testBlownPrecision() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, "SQLServer").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Bunny.class).addAnnotatedClass(PointyTooth.class).addAnnotatedClass(TwinkleToes.class).buildMetadata();
        boolean foundPointyToothCreate = false;
        boolean foundTwinkleToesCreate = false;
        List<String> commands = new SchemaCreatorImpl(ssr).generateCreationCommands(metadata, false);
        for (String command : commands) {
            log.debug(command);
            if (expectedSqlPointyTooth.equals(command)) {
                foundPointyToothCreate = true;
            } else if (expectedSqlTwinkleToes.equals(command)) {
                foundTwinkleToesCreate = true;
            }
        }
        assertTrue("Expected create table command for PointyTooth entity not found", foundPointyToothCreate);
        assertTrue("Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TwinkleToes(org.hibernate.test.annotations.id.sequences.entities.TwinkleToes) Bunny(org.hibernate.test.annotations.id.sequences.entities.Bunny) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 17 with Metadata

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

the class DiscriminatorOptionsTest method testPropertyBasedDiscriminatorForcing.

@Test
public void testPropertyBasedDiscriminatorForcing() throws Exception {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass2.class).addAnnotatedClass(SubClass2.class).getMetadataBuilder().enableImplicitForcingOfDiscriminatorsInSelect(true).build();
        PersistentClass persistentClass = metadata.getEntityBinding(BaseClass2.class.getName());
        assertNotNull(persistentClass);
        assertTrue(persistentClass instanceof RootClass);
        RootClass root = (RootClass) persistentClass;
        assertTrue("Discriminator should be forced by property", 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)

Example 18 with Metadata

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

the class DuplicatedDiscriminatorValueTest method tryBuildingSessionFactory.

private void tryBuildingSessionFactory(Class... annotatedClasses) {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
        for (Class annotatedClass : annotatedClasses) {
            metadataSources.addAnnotatedClass(annotatedClass);
        }
        final Metadata metadata = metadataSources.buildMetadata();
        final SessionFactory sessionFactory = metadata.buildSessionFactory();
        sessionFactory.close();
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 19 with Metadata

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

the class LongKeyNamingStrategyTest method testWithCustomNamingStrategy.

@Test
public void testWithCustomNamingStrategy() throws Exception {
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Address.class).addAnnotatedClass(Person.class).getMetadataBuilder().applyImplicitNamingStrategy(new LongIdentifierNamingStrategy()).build();
    org.hibernate.mapping.ForeignKey foreignKey = (org.hibernate.mapping.ForeignKey) metadata.getEntityBinding(Address.class.getName()).getTable().getForeignKeyIterator().next();
    assertEquals("FK_way_longer_than_the_30_char", foreignKey.getName());
    UniqueKey uniqueKey = metadata.getEntityBinding(Address.class.getName()).getTable().getUniqueKeyIterator().next();
    assertEquals("UK_way_longer_than_the_30_char", uniqueKey.getName());
    org.hibernate.mapping.Index index = metadata.getEntityBinding(Address.class.getName()).getTable().getIndexIterator().next();
    assertEquals("IDX_way_longer_than_the_30_cha", index.getName());
}
Also used : UniqueKey(org.hibernate.mapping.UniqueKey) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ForeignKey(javax.persistence.ForeignKey) Test(org.junit.Test)

Example 20 with Metadata

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

the class NamingStrategyTest method testWithJpaCompliantNamingStrategy.

@Test
public void testWithJpaCompliantNamingStrategy() throws Exception {
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(A.class).addAnnotatedClass(AddressEntry.class).getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
    Collection collectionBinding = metadata.getCollectionBinding(A.class.getName() + ".address");
    assertEquals("Expecting A#address collection table name (implicit) to be [A_address] per JPA spec (section 11.1.8)", "A_ADDRESS", collectionBinding.getCollectionTable().getQuotedName().toUpperCase(Locale.ROOT));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Collection(org.hibernate.mapping.Collection) Test(org.junit.Test)

Aggregations

Metadata (org.hibernate.boot.Metadata)99 MetadataSources (org.hibernate.boot.MetadataSources)88 Test (org.junit.Test)73 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)46 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)41 PersistentClass (org.hibernate.mapping.PersistentClass)29 TestForIssue (org.hibernate.testing.TestForIssue)24 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 Property (org.hibernate.mapping.Property)11 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)11 Collection (org.hibernate.mapping.Collection)10 RootClass (org.hibernate.mapping.RootClass)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 SessionFactory (org.hibernate.SessionFactory)8 Session (org.hibernate.Session)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 Properties (java.util.Properties)5