Search in sources :

Example 96 with MetadataSources

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

the class InvalidExtendedCdiSupportTest method testIt.

@Test
public void testIt() {
    Monitor.reset();
    final ExtendedBeanManagerImpl standIn = new ExtendedBeanManagerImpl();
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, standIn).build();
    final SessionFactoryImplementor sessionFactory;
    try {
        sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(ssr);
        throw e;
    }
    try {
        // The CDI bean should not be built immediately...
        assertFalse(Monitor.wasInstantiated());
        assertEquals(0, Monitor.currentCount());
        try {
            inTransaction(sessionFactory, session -> session.persist(new TheEntity(1)));
            inTransaction(sessionFactory, session -> {
                session.createQuery("delete TheEntity").executeUpdate();
            });
            fail("Expecting failure");
        } catch (IllegalStateException expected) {
        }
    } finally {
        sessionFactory.close();
    }
}
Also used : TheEntity(org.hibernate.test.cdi.events.TheEntity) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 97 with MetadataSources

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

the class InvalidNoCdiSupportTest method testIt.

@Test
public void testIt() {
    Monitor.reset();
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build();
    final SessionFactoryImplementor sessionFactory;
    try {
        // because there is no CDI available, building the SF should immediately
        // try to build the ManagedBeans which should fail here
        sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
        sessionFactory.close();
        fail("Expecting failure");
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(ssr);
        assertThat(e, instanceOf(InstantiationException.class));
    }
}
Also used : TheEntity(org.hibernate.test.cdi.events.TheEntity) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) InstantiationException(org.hibernate.InstantiationException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 98 with MetadataSources

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

the class SimpleXmlOverriddenTest method baseline.

/**
 * A baseline test, with an explicit @Convert annotation that should be in effect
 */
@Test
public void baseline() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
    PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
    Type type = pc.getProperty("it").getType();
    AttributeConverterTypeAdapter adapter = assertTyping(AttributeConverterTypeAdapter.class, type);
    assertTrue(SillyStringConverter.class.isAssignableFrom(adapter.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
}
Also used : StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 99 with MetadataSources

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

the class SimpleXmlOverriddenTest method testDefinitionAtAttributeLevel.

/**
 * Test outcome of applying overrides via orm.xml, specifically at the attribute level
 */
@Test
public void testDefinitionAtAttributeLevel() {
    // NOTE : simple-override.xml applied disable-conversion="true" at the attribute-level
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).addResource("org/hibernate/test/converter/simple-override.xml").buildMetadata();
    PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
    Type type = pc.getProperty("it").getType();
    assertTyping(StringType.class, type);
}
Also used : StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 100 with MetadataSources

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

the class CustomTypeConverterTest method testConverterAppliedScopedRegistration.

@Test
public void testConverterAppliedScopedRegistration() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(MyCustomConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        // now the new scoped way
        final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
        bootTypeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor(MyCustomJavaTypeDescriptor.INSTANCE);
        bootTypeConfiguration.getSqlTypeDescriptorRegistry().addDescriptor(MyCustomSqlTypeDescriptor.INSTANCE);
        performAssertions(metadataBuilder, bootTypeConfiguration);
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)293 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)193 Test (org.junit.Test)192 Metadata (org.hibernate.boot.Metadata)123 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)120 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)76 TestForIssue (org.hibernate.testing.TestForIssue)57 PersistentClass (org.hibernate.mapping.PersistentClass)53 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)41 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)37 Before (org.junit.Before)33 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)30 ServiceRegistry (org.hibernate.service.ServiceRegistry)26 RootClass (org.hibernate.mapping.RootClass)25 HashMap (java.util.HashMap)20 SimpleValue (org.hibernate.mapping.SimpleValue)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)20 File (java.io.File)19 Property (org.hibernate.mapping.Property)18 Map (java.util.Map)17