use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class CollectionAsBasicTest method testCollectionAsBasic.
@Test
public void testCollectionAsBasic() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Post.class).getMetadataBuilder().applyBasicType(new DelimitedStringsType()).build();
PersistentClass postBinding = metadata.getEntityBinding(Post.class.getName());
Property tagsAttribute = postBinding.getProperty("tags");
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class EnumeratedWithMappedSuperclassTest method testHHH10128.
@Test
public void testHHH10128() {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Entity.class).addAnnotatedClass(DescriptionEntity.class).addAnnotatedClass(AddressLevel.class).buildMetadata();
final PersistentClass addressLevelBinding = metadata.getEntityBinding(AddressLevel.class.getName());
final Property natureProperty = addressLevelBinding.getProperty("nature");
CustomType customType = assertTyping(CustomType.class, natureProperty.getType());
EnumType enumType = assertTyping(EnumType.class, customType.getUserType());
assertEquals(Types.VARCHAR, enumType.sqlTypes()[0]);
SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
try {
EntityPersister p = sf.getEntityPersister(AddressLevel.class.getName());
CustomType runtimeType = assertTyping(CustomType.class, p.getPropertyType("nature"));
EnumType runtimeEnumType = assertTyping(EnumType.class, runtimeType.getUserType());
assertEquals(Types.VARCHAR, runtimeEnumType.sqlTypes()[0]);
} finally {
sf.close();
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class OrmXmlEnumTypeTest method testOrmXmlDefinedEnumType.
@Test
public void testOrmXmlDefinedEnumType() {
StandardServiceRegistry ssr = ServiceRegistryBuilder.buildServiceRegistry();
try {
MetadataSources ms = new MetadataSources(ssr);
ms.addResource("org/hibernate/test/annotations/enumerated/ormXml/orm.xml");
Metadata metadata = ms.buildMetadata();
Type bindingPropertyType = metadata.getEntityBinding(BookWithOrmEnum.class.getName()).getProperty("bindingStringEnum").getType();
CustomType customType = ExtraAssertions.assertTyping(CustomType.class, bindingPropertyType);
EnumType enumType = ExtraAssertions.assertTyping(EnumType.class, customType.getUserType());
assertFalse(enumType.isOrdinal());
} finally {
ServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class FetchProfileTest method testWrongClass.
@Test
public void testWrongClass() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer3.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class FetchProfileTest method testUnsupportedFetchMode.
@Test
public void testUnsupportedFetchMode() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer4.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
Aggregations