IdentityObjectAttributeMetaData amd = mdMap != null ? mdMap.get(attribute.getName()) : null;
// Default to text
String type = amd != null ? amd.getType() : IdentityObjectAttributeMetaData.TEXT_TYPE;
HibernateIdentityObjectAttribute hibernateAttribute = null;
for (HibernateIdentityObjectAttribute storeAttribute : hibernateObject.getAttributes())
{
if (storeAttribute.getName().equals(name))
{
hibernateAttribute = storeAttribute;
break;
}
}
if (hibernateAttribute != null)
{
if (hibernateAttribute instanceof HibernateIdentityObjectTextAttribute)
{
if (!type.equals(IdentityObjectAttributeMetaData.TEXT_TYPE))
{
throw new IdentityException("Wrong attribute mapping. Attribute persisted as text is mapped with: "
+ type + ". Attribute name: " + name);
}
Set<String> mergedValues = new HashSet<String>(hibernateAttribute.getValues());
for (Object value : attribute.getValues())
{
mergedValues.add(value.toString());
}
((HibernateIdentityObjectTextAttribute)hibernateAttribute).setValues(mergedValues);
}
else if (hibernateAttribute instanceof HibernateIdentityObjectBinaryAttribute)
{
if (!type.equals(IdentityObjectAttributeMetaData.BINARY_TYPE))
{
throw new IdentityException("Wrong attribute mapping. Attribute persisted as binary is mapped with: "
+ type + ". Attribute name: " + name);
}
Set<byte[]> mergedValues = new HashSet<byte[]>(hibernateAttribute.getValues());
for (Object value : attribute.getValues())
{
mergedValues.add((byte[])value);
}