use of org.hibernate.type.SerializableToBlobType 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());
}
use of org.hibernate.type.SerializableToBlobType in project hibernate-orm by hibernate.
the class BasicMetadataGenerator method addBasic.
@SuppressWarnings({ "unchecked" })
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
final Type type = value.getType();
if (type instanceof BasicType || type instanceof SerializableToBlobType || "org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
if (parent != null) {
final boolean addNestedType = (value instanceof SimpleValue) && ((SimpleValue) value).getTypeParameters() != null;
String typeName = type.getName();
if (typeName == null) {
typeName = type.getClass().getName();
}
final Element propMapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(), addNestedType ? null : typeName, propertyAuditingData.isForceInsertable() || insertable, key);
MetadataTools.addColumns(propMapping, value.getColumnIterator());
if (addNestedType) {
final Properties typeParameters = ((SimpleValue) value).getTypeParameters();
final Element typeMapping = propMapping.addElement("type");
typeMapping.addAttribute("name", typeName);
if ("org.hibernate.type.EnumType".equals(typeName)) {
// Proper handling of enumeration type
mapEnumerationType(typeMapping, type, typeParameters);
} else {
// By default copying all Hibernate properties
for (Object object : typeParameters.keySet()) {
final String keyType = (String) object;
final String property = typeParameters.getProperty(keyType);
if (property != null) {
typeMapping.addElement("param").addAttribute("name", keyType).setText(property);
}
}
}
}
}
// A null mapper means that we only want to add xml mappings
if (mapper != null) {
mapper.add(propertyAuditingData.getPropertyData());
}
} else {
return false;
}
return true;
}
Aggregations