Search in sources :

Example 61 with Metadata

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

the class ParameterizedAttributeConverterParameterTypeTest method testNestedTypeParameterAutoApplication.

@Test
@TestForIssue(jiraKey = "HHH-10050")
public void testNestedTypeParameterAutoApplication() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(SampleEntity.class).getMetadataBuilder().applyAttributeConverter(IntegerListConverter.class).applyAttributeConverter(StringListConverter.class).build();
    // lets make sure the auto-apply converters were applied properly...
    PersistentClass pc = metadata.getEntityBinding(SampleEntity.class.getName());
    {
        Property prop = pc.getProperty("someStrings");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTrue(StringListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
    }
    {
        Property prop = pc.getProperty("someIntegers");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTrue(IntegerListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
    }
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 62 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());
    assertFalse(metadata.getEntityBinding(AEntity.class.getName()).isCached());
    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 63 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();
    assertFalse(metadata.getEntityBinding(ABase.class.getName()).isCached());
    assertTrue(metadata.getEntityBinding(AEntity.class.getName()).isCached());
    assertFalse(triggerable.wasTriggered());
    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 64 with Metadata

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

the class GetAndIsVariantGetterTest method testInstanceStaticConflict.

@Test
@TestForIssue(jiraKey = "HHH-12046")
public void testInstanceStaticConflict() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(InstanceStaticEntity.class).buildMetadata();
    assertNotNull(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).getIdentifier());
    assertNotNull(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).getIdentifierProperty());
    assertTrue(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).hasProperty("foo"));
    ReflectHelper.findGetterMethod(InstanceStaticEntity.class, "foo");
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 65 with Metadata

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

the class TransactionsTest method jdbc.

@Test
public void jdbc() {
    // tag::transactions-api-jdbc-example[]
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jdbc").build();
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).getMetadataBuilder().build();
    SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build();
    Session session = sessionFactory.openSession();
    try {
        // calls Connection#setAutoCommit( false ) to
        // signal start of transaction
        session.getTransaction().begin();
        session.createQuery("UPDATE customer set NAME = 'Sir. '||NAME").executeUpdate();
        // calls Connection#commit(), if an error
        // happens we attempt a rollback
        session.getTransaction().commit();
    } catch (Exception e) {
        // where the exception happened
        if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE || session.getTransaction().getStatus() == TransactionStatus.MARKED_ROLLBACK) {
            session.getTransaction().rollback();
        }
    // handle the underlying error
    } finally {
        session.close();
        sessionFactory.close();
    }
// end::transactions-api-jdbc-example[]
}
Also used : SessionFactory(org.hibernate.SessionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) 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