Search in sources :

Example 11 with Metadata

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

the class MetadataTest method testBuildingMetamodelWithParameterizedCollection.

@Test
@SuppressWarnings({ "unchecked" })
public void testBuildingMetamodelWithParameterizedCollection() {
    Metadata metadata = new MetadataSources().addAnnotatedClass(WithGenericCollection.class).buildMetadata();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory();
    MetamodelImpl metamodel = new MetamodelImpl(sfi);
    metamodel.initialize((MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED);
    sfi.close();
}
Also used : MetamodelImpl(org.hibernate.metamodel.internal.MetamodelImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 12 with Metadata

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

the class GetAndIsVariantGetterTest method testAnnotationsFieldAccess.

@Test
@TestForIssue(jiraKey = "HHH-10309")
public void testAnnotationsFieldAccess() {
    // this one should be ok because the AccessType is FIELD
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(AnotherEntity.class).buildMetadata();
    assertNotNull(metadata.getEntityBinding(AnotherEntity.class.getName()).getIdentifier());
    assertNotNull(metadata.getEntityBinding(AnotherEntity.class.getName()).getIdentifierProperty());
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with Metadata

use of org.hibernate.boot.Metadata 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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 14 with Metadata

use of org.hibernate.boot.Metadata 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();
    }
}
Also used : CustomType(org.hibernate.type.CustomType) EntityPersister(org.hibernate.persister.entity.EntityPersister) EnumType(org.hibernate.type.EnumType) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 15 with Metadata

use of org.hibernate.boot.Metadata 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);
    }
}
Also used : CustomType(org.hibernate.type.CustomType) CustomType(org.hibernate.type.CustomType) EnumType(org.hibernate.type.EnumType) Type(org.hibernate.type.Type) EnumType(org.hibernate.type.EnumType) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) 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