Search in sources :

Example 1 with MetadataImpl

use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.

the class BasicModelingTest method testMetamodelBuilding.

@Test
@TestForIssue(jiraKey = "HHH-9042")
public void testMetamodelBuilding() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Person.class).getMetadataBuilder().applyAttributeConverter(SexConverter.class).build();
        ((MetadataImpl) metadata).validate();
        PersistentClass personBinding = metadata.getEntityBinding(Person.class.getName());
        assertNotNull(personBinding);
        PersistentClass personAuditBinding = metadata.getEntityBinding(Person.class.getName() + "_AUD");
        assertNotNull(personAuditBinding);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : MetadataImpl(org.hibernate.boot.internal.MetadataImpl) 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) AbstractEnversTest(org.hibernate.envers.test.AbstractEnversTest) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with MetadataImpl

use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.

the class GeneratedValueTest method testGeneratedUuidId.

@Test
public void testGeneratedUuidId() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
        ((MetadataImpl) metadata).validate();
        PersistentClass entityBinding = metadata.getEntityBinding(TheEntity.class.getName());
        assertEquals(UUID.class, entityBinding.getIdentifier().getType().getReturnedClass());
        IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator(metadata.getIdentifierGeneratorFactory(), metadata.getDatabase().getDialect(), null, null, (RootClass) entityBinding);
        assertTyping(UUIDGenerator.class, generator);
        // now a functional test
        SessionFactory sf = metadata.buildSessionFactory();
        try {
            TheEntity theEntity = new TheEntity();
            Session s = sf.openSession();
            s.beginTransaction();
            s.save(theEntity);
            s.getTransaction().commit();
            s.close();
            assertNotNull(theEntity.id);
            s = sf.openSession();
            s.beginTransaction();
            try {
                s.delete(theEntity);
                s.getTransaction().commit();
            } catch (Exception e) {
                s.getTransaction().rollback();
                throw e;
            } finally {
                s.close();
            }
        } finally {
            try {
                sf.close();
            } catch (Exception ignore) {
            }
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) MetadataImpl(org.hibernate.boot.internal.MetadataImpl) 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) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with MetadataImpl

use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.

the class AndNationalizedTests method basicTest.

@Test
@TestForIssue(jiraKey = "HHH-9599")
public void basicTest() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
        ((MetadataImpl) metadata).validate();
        final PersistentClass entityBinding = metadata.getEntityBinding(TestEntity.class.getName());
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertEquals(Types.VARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
        } else {
            assertEquals(Types.NVARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : MetadataImpl(org.hibernate.boot.internal.MetadataImpl) 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) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Metadata (org.hibernate.boot.Metadata)3 MetadataSources (org.hibernate.boot.MetadataSources)3 MetadataImpl (org.hibernate.boot.internal.MetadataImpl)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 Test (org.junit.Test)3 TestForIssue (org.hibernate.testing.TestForIssue)2 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 PostgreSQL81Dialect (org.hibernate.dialect.PostgreSQL81Dialect)1 AbstractEnversTest (org.hibernate.envers.test.AbstractEnversTest)1 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)1