I have below code in my spring-boot application . We are not getting any exception at startup but while creating attribute I am getting below exception like
Caused by: org.hibernate.search.util.common.SearchException: HSEARCH400609: Unknown field ‘attributes.archetype.archetypeId’.
I am not sure if I miss anything else…
Resource.java(Entity class)
@MapKeyColumn(name = "attribute_name")
@Column(name = "attribute_value", nullable = false, length = 5000)
@PropertyBinding(binder = @PropertyBinderRef(type = ResourceAttributesBinder.class))
@Convert(attributeName = "value", converter = JSONObjectConverter.class)
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OptimisticLock(excluded = true)
private Map<String, JSONObject> attributes;
ResourceAttributesBinder.java
public class ResourceAttributesBinder implements PropertyBinder {
@Override
public void bind(PropertyBindingContext context) {
context.dependencies().useRootOnly();
PojoModelProperty bridgedElement = context.bridgedElement();
IndexSchemaObjectField attributeField = context.indexSchemaElement()
.objectField( bridgedElement.name() );
context.bridge(Map.class,new ResourceAttributesPropertyBridge(attributeField.toReference()));
}
}
ResourceAttributesPropertyBridge.java
public class ResourceAttributesPropertyBridge implements PropertyBridge<Map> {
private final IndexObjectFieldReference fieldReference;
public ResourceAttributesPropertyBridge(IndexObjectFieldReference fieldReference) {
this.fieldReference = fieldReference;
}
@Override
public void write(DocumentElement target, Map bridgedElement, PropertyBridgeWriteContext context) {
System.out.println("######bridgedElement#######"+ bridgedElement);
final Map<String, Object> indexMap = (Map<String, Object>) bridgedElement;
DocumentElement indexedAttributeMetadata = target.addObject( fieldReference );
if (!ObjectUtils.isEmpty(indexMap)) {
for (Map.Entry<String, Object> entry : indexMap.entrySet()) {
final List<String> attributeKeys = getIndexedAttributes().get(entry.getKey());
if (!ObjectUtils.isEmpty(attributeKeys)) {
final Map<String, Object> resourceAttributes = (Map<String, Object>) entry.getValue();
for (String attributeKey : attributeKeys) {
final Object attributeValue = resourceAttributes.get(attributeKey);
final String fieldName = entry.getKey() + "." + attributeKey;
if (!ObjectUtils.isEmpty(attributeValue)) {
if (attributeValue instanceof List) {
((List<String>) attributeValue).forEach(item -> {
if (log.isTraceEnabled()) {
log.trace("Adding field {} with value {} to document.", fieldName, item);
}
System.out.println("fieldName1=="+fieldName);
System.out.println("attributeValue1=="+attributeValue.toString());
indexedAttributeMetadata.addValue(fieldName,item);
// luceneOptions.addFieldToDocument(fieldName, item, document);
});
} else {
if (log.isTraceEnabled()) {
log.trace("Adding field {} with value {} to document.", fieldName, attributeValue.toString());
}
System.out.println("fieldName1=="+fieldName);
System.out.println("attributeValue1=="+attributeValue.toString());
indexedAttributeMetadata.addValue(fieldName,attributeValue.toString());
// luceneOptions.addFieldToDocument(fieldName, attributeValue.toString(), document);
}
}
}
}
}
}
}
}