Search in sources :

Example 31 with PersistentClass

use of org.hibernate.mapping.PersistentClass 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 32 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class BasicAttributeOverrideTest method testIt.

@Test
@TestForIssue(jiraKey = "HHH-8630")
public void testIt() {
    final PersistentClass entityBinding = metadata().getEntityBinding(AggregatedTypeValue.class.getName());
    final Property attributesBinding = entityBinding.getProperty("attributes");
    final org.hibernate.mapping.Map attributesMap = (org.hibernate.mapping.Map) attributesBinding.getValue();
    final SimpleValue mapKey = assertTyping(SimpleValue.class, attributesMap.getIndex());
    final BasicType mapKeyType = assertTyping(BasicType.class, mapKey.getType());
    assertTrue(String.class.equals(mapKeyType.getReturnedClass()));
    // let's also make sure the @MapKeyColumn got applied
    assertThat(mapKey.getColumnSpan(), is(1));
    final org.hibernate.mapping.Column mapKeyColumn = assertTyping(org.hibernate.mapping.Column.class, mapKey.getColumnIterator().next());
    assertThat(mapKeyColumn.getName(), equalTo("attribute_name"));
}
Also used : BasicType(org.hibernate.type.BasicType) Property(org.hibernate.mapping.Property) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 33 with PersistentClass

use of org.hibernate.mapping.PersistentClass 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 34 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class EnumeratedSmokeTest method testEnumeratedTypeResolutions.

/**
	 * I personally have been unable to repeoduce the bug as reported in HHH-10402.  This test
	 * is equivalent to what the reporters say happens, but these tests pass fine.
	 */
@Test
@TestForIssue(jiraKey = "HHH-10402")
public void testEnumeratedTypeResolutions() {
    final MetadataImplementor mappings = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(EntityWithEnumeratedAttributes.class).buildMetadata();
    mappings.validate();
    final PersistentClass entityBinding = mappings.getEntityBinding(EntityWithEnumeratedAttributes.class.getName());
    validateEnumMapping(entityBinding.getProperty("notAnnotated"), EnumType.ORDINAL);
    validateEnumMapping(entityBinding.getProperty("noEnumType"), EnumType.ORDINAL);
    validateEnumMapping(entityBinding.getProperty("ordinalEnumType"), EnumType.ORDINAL);
    validateEnumMapping(entityBinding.getProperty("stringEnumType"), EnumType.STRING);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 35 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class SerializableToBlobTypeTest method testTypeDefinition.

@Test
public void testTypeDefinition() {
    PersistentClass pc = metadata().getEntityBinding(EntitySerialize.class.getName());
    // explicitLob of SerializableToBlobType
    Type explicitLobType = pc.getProperty("explicitLob").getType();
    assertEquals(ExplicitSerializable.class, explicitLobType.getReturnedClass());
    assertEquals(SerializableToBlobType.class.getName(), explicitLobType.getName());
    // explicit of ExplicitSerializableType
    Type explicitType = pc.getProperty("explicit").getType();
    assertEquals(ExplicitSerializable.class, explicitType.getReturnedClass());
    assertEquals(ExplicitSerializableType.class.getName(), explicitType.getName());
    // implicit of ImplicitSerializableType
    Type implicitType = pc.getProperty("implicit").getType();
    assertEquals(ImplicitSerializable.class, implicitType.getReturnedClass());
    assertEquals(ImplicitSerializableType.class.getName(), implicitType.getName());
    // explicitOverridingImplicit ExplicitSerializableType overrides ImplicitSerializableType
    Type overrideType = pc.getProperty("explicitOverridingImplicit").getType();
    assertEquals(ImplicitSerializable.class, overrideType.getReturnedClass());
    assertEquals(ExplicitSerializableType.class.getName(), overrideType.getName());
}
Also used : SerializableToBlobType(org.hibernate.type.SerializableToBlobType) Type(org.hibernate.type.Type) SerializableToBlobType(org.hibernate.type.SerializableToBlobType) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Aggregations

PersistentClass (org.hibernate.mapping.PersistentClass)140 Test (org.junit.Test)70 Property (org.hibernate.mapping.Property)52 MetadataSources (org.hibernate.boot.MetadataSources)36 Column (org.hibernate.mapping.Column)36 Metadata (org.hibernate.boot.Metadata)28 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)26 Iterator (java.util.Iterator)25 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)24 SimpleValue (org.hibernate.mapping.SimpleValue)19 MappingException (org.hibernate.MappingException)18 Collection (org.hibernate.mapping.Collection)18 TestForIssue (org.hibernate.testing.TestForIssue)18 Component (org.hibernate.mapping.Component)17 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)15 AnnotationException (org.hibernate.AnnotationException)14 RootClass (org.hibernate.mapping.RootClass)14 Table (org.hibernate.mapping.Table)14 HashMap (java.util.HashMap)13 Type (org.hibernate.type.Type)13