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