Search in sources :

Example 1 with EnumType

use of org.hibernate.type.EnumType 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 2 with EnumType

use of org.hibernate.type.EnumType 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)

Example 3 with EnumType

use of org.hibernate.type.EnumType in project hibernate-orm by hibernate.

the class EnumeratedTypeTest method testTypeDefinition.

@Test
public void testTypeDefinition() {
    PersistentClass pc = metadata().getEntityBinding(EntityEnum.class.getName());
    // ordinal default of EnumType
    Type ordinalEnum = pc.getProperty("ordinal").getType();
    assertEquals(Common.class, ordinalEnum.getReturnedClass());
    assertEquals(EnumType.class.getName(), ordinalEnum.getName());
    // string defined by Enumerated(STRING)
    Type stringEnum = pc.getProperty("string").getType();
    assertEquals(Common.class, stringEnum.getReturnedClass());
    assertEquals(EnumType.class.getName(), stringEnum.getName());
    // explicit defined by @Type
    Type first = pc.getProperty("firstLetter").getType();
    assertEquals(FirstLetter.class, first.getReturnedClass());
    assertEquals(FirstLetterType.class.getName(), first.getName());
    // implicit defined by @TypeDef in somewhere
    Type last = pc.getProperty("lastNumber").getType();
    assertEquals(LastNumber.class, last.getReturnedClass());
    assertEquals(LastNumberType.class.getName(), last.getName());
    // implicit defined by @TypeDef in anywhere, but overrided by Enumerated(STRING)
    Type implicitOverrideExplicit = pc.getProperty("explicitOverridingImplicit").getType();
    assertEquals(LastNumber.class, implicitOverrideExplicit.getReturnedClass());
    assertEquals(EnumType.class.getName(), implicitOverrideExplicit.getName());
}
Also used : FirstLetterType(org.hibernate.test.annotations.enumerated.custom_types.FirstLetterType) EnumType(org.hibernate.type.EnumType) LastNumberType(org.hibernate.test.annotations.enumerated.custom_types.LastNumberType) Type(org.hibernate.type.Type) LastNumberType(org.hibernate.test.annotations.enumerated.custom_types.LastNumberType) EnumType(org.hibernate.type.EnumType) FirstLetterType(org.hibernate.test.annotations.enumerated.custom_types.FirstLetterType) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Aggregations

EnumType (org.hibernate.type.EnumType)3 Test (org.junit.Test)3 Metadata (org.hibernate.boot.Metadata)2 MetadataSources (org.hibernate.boot.MetadataSources)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 CustomType (org.hibernate.type.CustomType)2 Type (org.hibernate.type.Type)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 Property (org.hibernate.mapping.Property)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 FirstLetterType (org.hibernate.test.annotations.enumerated.custom_types.FirstLetterType)1 LastNumberType (org.hibernate.test.annotations.enumerated.custom_types.LastNumberType)1