Hibernate Search 6 doesn't support BigDecimal primary keys?

We’re trying to upgrade from Hibernate Search v.5 to v.6.

Our JPAs use BigDecimal (not Long) as our primary key / @Id.

Hibernate Search 5 handles this fine, and but Hibernate Search 6 gives this error:

org.hibernate.search.util.common.SearchException: HSEARCH700001: Unable to find a default identifier bridge implementation for type 'java.math.BigDecimal'
	at org.hibernate.search.mapper.pojo.bridge.mapping.impl.BridgeResolver.resolveIdentifierBinderForType(BridgeResolver.java:113)
	at org.hibernate.search.mapper.pojo.mapping.building.impl.PojoIndexModelBinderImpl.bindIdentifier(PojoIndexModelBinderImpl.java:87)
...

I tried to create a bridge class that implements IdentifierBridge, to work around this:

public class DocumentIdBridge implements IdentifierBridge<BigDecimal> {
    @Override
    public String toDocumentIdentifier(BigDecimal value, IdentifierBridgeToDocumentIdentifierContext context) { 
        return value.toString();
    }

    @Override
    public BigDecimal fromDocumentIdentifier(String documentIdentifier, IdentifierBridgeFromDocumentIdentifierContext context) { 
        return new BigDecimal(documentIdentifier);
    }
}

but your @IndentifierBridgeRef.type complains that “The value for annotation attribute DocumentId.identifierBridge must be some @org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef annotation”.

How do I resolve this?

This looks like a compiler error, not a Hibernate Search error.

Please show me your @DocumentId annotation, and the stack trace if any.

By the way, if the built-in default bridges are not enough for you, you can register your own, so you don’t have to use @DocumentId(identifierBridge = ...) everywhere. See this section of the documentation.

Hi @yrodiere.
Awww, I was missing

import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef;

It works now, and I’m able to index entities with BigDecimal primary keys as follows:

@Id
@DocumentId(identifierBridge = @IdentifierBridgeRef(type = DocumentIdBridge.class))
private BigDecimal id;

where DocumentIdBridge.java is as follows:

...
public class DocumentIdBridge implements IdentifierBridge<BigDecimal> {
    @Override
    public String toDocumentIdentifier(BigDecimal value, IdentifierBridgeToDocumentIdentifierContext context) { 
        return value.toString();
    }

    @Override
    public BigDecimal fromDocumentIdentifier(String documentIdentifier, IdentifierBridgeFromDocumentIdentifierContext context) { 
        return new BigDecimal(documentIdentifier);
    }
}

Thanks for your suggestion to define a built-in bridge. I created the following class to point to my DocumentIdBridge.java from above:

public class MySearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer {
    @Override
    public void configure(HibernateOrmMappingConfigurationContext context) {
        context.bridges().exactType(BigDecimal.class).identifierBridge(new DocumentIdBridge()); 
    }
}

and I added this line to my hibernate.properties file:

hibernate.search.mapping.configurer my.package.MySearchMappingConfigurer

Does MySearchMappingConfigurer.java look ok to you? Did I wire everything correctly in my configure() method?

It looks OK to me, but your compiler will know best :slight_smile:

Just remove the @DocumentId(identifierBridge = @IdentifierBridgeRef(type = DocumentIdBridge.class)) annotation from your id property. If Hibernate Search still boots without any exception, then you’ll know that your mapping configurer works correctly.

2 posts were split to a new topic: Changing the analyzer used by @FullTextField by default