Search in sources :

Example 26 with Metadata

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

the class UniqueConstraintUnitTests method testUnNamedConstraints.

@Test
@TestForIssue(jiraKey = "HHH-8026")
public void testUnNamedConstraints() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UniqueNoNameA.class).addAnnotatedClass(UniqueNoNameB.class).buildMetadata();
        org.hibernate.mapping.Table tableA = null;
        org.hibernate.mapping.Table tableB = null;
        for (org.hibernate.mapping.Table table : metadata.collectTableMappings()) {
            if (table.getName().equals("UniqueNoNameA")) {
                tableA = table;
            } else if (table.getName().equals("UniqueNoNameB")) {
                tableB = table;
            }
        }
        assertTrue("Could not find the expected tables.", tableA != null && tableB != null);
        assertFalse(tableA.getUniqueKeyIterator().next().getName().equals(tableB.getUniqueKeyIterator().next().getName()));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 27 with Metadata

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

the class NonRootEntityWithCacheAnnotationTest method testCacheOnNonRootEntity.

@Test
public void testCacheOnNonRootEntity() {
    Map settings = new HashMap();
    settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
    assertTrue(triggerable.wasTriggered());
    assertNull((metadata.getEntityBinding(AEntity.class.getName())).getCacheConcurrencyStrategy());
    serviceRegistry.destroy();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with Metadata

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

the class NonRootEntityWithCacheableAnnotationTest method testCacheableOnNonRootEntity.

@Test
public void testCacheableOnNonRootEntity() {
    Map settings = new HashMap();
    settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    settings.put(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write");
    settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
    assertTrue(triggerable.wasTriggered());
    assertNull((metadata.getEntityBinding(AEntity.class.getName())).getCacheConcurrencyStrategy());
    serviceRegistry.destroy();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with Metadata

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

the class MultipleBagFetchTest method testEntityWithMultipleJoinFetchedBags.

@Test
public void testEntityWithMultipleJoinFetchedBags() {
    StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
    Metadata metadata = new MetadataSources(standardRegistry).addAnnotatedClass(Post.class).addAnnotatedClass(PostComment.class).addAnnotatedClass(Tag.class).getMetadataBuilder().build();
    try {
        metadata.buildSessionFactory();
        fail("MultipleBagFetchException should have been thrown.");
    } catch (MultipleBagFetchException expected) {
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 30 with Metadata

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

the class AnnotationBinderTest method testInvalidPrimaryKeyJoinColumnAnnotationMessageContainsClassName.

@Test
public void testInvalidPrimaryKeyJoinColumnAnnotationMessageContainsClassName() throws Exception {
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000137");
    StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
    Metadata metadata = new MetadataSources(srb.build()).addAnnotatedClass(InvalidPrimaryKeyJoinColumnAnnotationEntity.class).buildMetadata();
    assertTrue("Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered());
    assertTrue("Expected invalid class name in warning HHH00137 message but it does not apper to be present; got " + triggerable.triggerMessage(), triggerable.triggerMessage().matches(".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*"));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Triggerable(org.hibernate.testing.logger.Triggerable) 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