Search in sources :

Example 86 with Metadata

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

the class SchemaToolTransactionHandlingTest method testValidateInExistingJtaTransaction.

@Test
public void testValidateInExistingJtaTransaction() {
    // start a JTA transaction...
    try {
        TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    } catch (Exception e) {
        throw new RuntimeException("Unable to being JTA transaction prior to starting test", e);
    }
    // hold reference to Transaction object
    final Transaction jtaTransaction;
    try {
        jtaTransaction = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().getTransaction();
    } catch (SystemException e) {
        throw new RuntimeException("Unable to access JTA Transaction prior to starting test", e);
    }
    final StandardServiceRegistry registry = buildJtaStandardServiceRegistry();
    // perform the test...
    try {
        final SchemaManagementTool smt = registry.getService(SchemaManagementTool.class);
        final Metadata mappings = buildMappings(registry);
        // first make the schema exist...
        try {
            smt.getSchemaCreator(Collections.emptyMap()).doCreation(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
        } catch (Exception e) {
            throw new RuntimeException("Unable to create schema to validation tests", e);
        }
        try {
            smt.getSchemaValidator(Collections.emptyMap()).doValidation(mappings, ExecutionOptionsTestImpl.INSTANCE);
        } finally {
            try {
                smt.getSchemaDropper(Collections.emptyMap()).doDrop(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
            } catch (Exception ignore) {
            // ignore
            }
        }
    } finally {
        try {
            jtaTransaction.commit();
            ((StandardServiceRegistryImpl) registry).destroy();
        } catch (Exception e) {
        // not much we can do...
        }
    }
}
Also used : SchemaManagementTool(org.hibernate.tool.schema.spi.SchemaManagementTool) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) Metadata(org.hibernate.boot.Metadata) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) CommandAcceptanceException(org.hibernate.tool.schema.spi.CommandAcceptanceException) SystemException(javax.transaction.SystemException) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 87 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.entities.TwinkleToes) Bunny(org.hibernate.test.annotations.id.entities.Bunny) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 88 with Metadata

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

the class ExtendsTest method testUnionSubclass.

@Test
public void testUnionSubclass() {
    Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/unionsubclass.hbm.xml").buildMetadata();
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 89 with Metadata

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

the class ExtendsTest method testNwaitingForSuper.

@Test
public void testNwaitingForSuper() {
    Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml").buildMetadata();
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Employee"));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 90 with Metadata

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

the class ExtendsTest method testJoinedSubclassAndEntityNamesOnly.

@Test
public void testJoinedSubclassAndEntityNamesOnly() {
    Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/entitynames.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)

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