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();
}
}
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));
}
}
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()));
}
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);
}
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);
}
}
Aggregations