Search in sources :

Example 21 with Metadata

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

the class NullablePrimaryKeyTest method testGeneratedSql.

@Test
@SuppressWarnings("unchecked")
public void testGeneratedSql() {
    Map settings = new HashMap();
    settings.putAll(Environment.getProperties());
    settings.put(AvailableSettings.DIALECT, SQLServerDialect.class.getName());
    ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(settings);
    try {
        MetadataSources ms = new MetadataSources(serviceRegistry);
        ms.addAnnotatedClass(Address.class);
        ms.addAnnotatedClass(Person.class);
        final Metadata metadata = ms.buildMetadata();
        final List<String> commands = new SchemaCreatorImpl(serviceRegistry).generateCreationCommands(metadata, false);
        for (String s : commands) {
            log.debug(s);
        }
        String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0), " + "person_id numeric(19,0) not null, primary key (person_id))";
        Assert.assertEquals("Wrong SQL", expectedMappingTableSql, commands.get(2));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        ServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SQLServerDialect(org.hibernate.dialect.SQLServerDialect) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistry(org.hibernate.service.ServiceRegistry) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 22 with Metadata

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

the class InheritedAttributeOverridingTest method testInheritedAttributeOverridingEntity.

@Test
@TestForIssue(jiraKey = "HHH-9485")
public void testInheritedAttributeOverridingEntity() {
    Metadata metadata = new MetadataSources(standardServiceRegistry).addAnnotatedClass(C.class).addAnnotatedClass(D.class).buildMetadata();
    ((MetadataImplementor) metadata).validate();
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 23 with Metadata

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

the class MySQLDropConstraintThrowsExceptionTest method setUp.

@Before
public void setUp() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
    SessionFactoryImplementor sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Before(org.junit.Before)

Example 24 with Metadata

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

the class MySQLDropConstraintThrowsExceptionTest method tearDown.

@After
public void tearDown() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
    SessionFactoryImplementor sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) After(org.junit.After)

Example 25 with Metadata

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

the class MySQLDropConstraintThrowsExceptionTest method testEnumTypeInterpretation.

@Test
public void testEnumTypeInterpretation() {
    final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "update").applySetting(AvailableSettings.CONNECTION_PROVIDER, connectionProvider).build();
    SessionFactory sessionFactory = null;
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
        List<String> alterStatements = connectionProvider.getExecuteStatements().stream().filter(sql -> sql.toLowerCase().contains("alter ")).map(String::trim).collect(Collectors.toList());
        assertTrue(alterStatements.get(0).matches("alter table CUSTOMER\\s+drop index .*?"));
        assertTrue(alterStatements.get(1).matches("alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)"));
    } finally {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PreparedStatementSpyConnectionProvider(org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) 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