Suggestion : raise an exception when HSearch annotation is present on unrecognized method

Hi searchers,

I did a lot of indexation yet. And I met a use case that not satisfied me a lot : the “error” may be silent.
Indeed, when you simply annotate a method, with unconventional naming, you have to think that all your HSearch annotations on this method are ignored.
The method’s name must start with “isXXX” or “getXXXX”. I annotated for example this method :

@GenericField
    @IndexingDependency(derivedFrom = {
            @ObjectPath({@PropertyValue(propertyName = Acte_.REPRISE)}),
            @ObjectPath({@PropertyValue(propertyName = Acte_.ACTE_MICEN), @PropertyValue(propertyName = ActeMicen_.SYNCHRONISE)})
    })
public boolean mustBeMicenSynchronized() {
        return this.acteMicen != null
                && Boolean.TRUE.equals(this.getReprise())
                && !Boolean.TRUE.equals(this.acteMicen.getSynchronise());
    }

instead of doing like this :

public boolean mustBeMicenSynchronized() {
        return this.acteMicen != null
                && Boolean.TRUE.equals(this.getReprise())
                && !Boolean.TRUE.equals(this.acteMicen.getSynchronise());
    }

@GenericField
    @IndexingDependency(derivedFrom = {
            @ObjectPath({@PropertyValue(propertyName = Acte_.REPRISE)}),
            @ObjectPath({@PropertyValue(propertyName = Acte_.ACTE_MICEN), @PropertyValue(propertyName = ActeMicen_.SYNCHRONISE)})
    })
public boolean isMustBeMicenSynchronized() {
        return mustBeMicenSynchronized();
    }

So no error at present. The mass indexer do its job.
Moreover, I never query on this field named “mustBeMicenSynchronized” as I expect. So all is good. (although this index property never exist).
I did then my complex query, it results my projection object mapping the response.
This object never receive a “MustBeMicenSynchronized” property, so no mapping and it will be always null…always that the problem. In fact, the property was never indexed, my test :

If (Boolean.TRUE.equals(mustBeMicenSynchronized)) {
//...some operations
}

will be always false. The error was at indexation time.

What do you think of it ?

Hi,

Thanks for your feedback. That’s a good idea, I created [HSEARCH-4344] Log a warning or throw an error for Hibernate Search annotations on methods with unsupported name or arguments - Hibernate JIRA to track it.

Of course the problem will be the implementation; we ignore such method for a reason, and the reason is the underlying library used to retrieve a list of properties (Hibernate Commons Annotations) simply ignores such methods. In order to detect the problematic methods, we would have to bypass that library and actively look for ignored methods, then look for Hibernate Search properties on those methods…

Anyway, whoever works on that will have to be creative :slight_smile: