# Hibernate Search 6 doesn't support BigDecimal primary keys?

**URL:** <https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712>\
**Category:** Hibernate Search\
**Created:** [September 16, 2021, 6:34pm UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712 "2021-09-16T18:34:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dimitri/32/513_2.png) [@Dimitri](https://discourse.hibernate.org/u/Dimitri)\
**Post date:** [September 16, 2021, 6:34pm UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712/1 "2021-09-16T18:34:54Z")

</div>

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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [September 17, 2021, 6:15am UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712/2 "2021-09-17T06:15:44Z")

</div>

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](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#_bridgeprovider_associate_a_bridge_to_a_given_return_type).

---

<div class="post-metadata">

**Author:** ![Dimitri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dimitri/32/513_2.png) [@Dimitri](https://discourse.hibernate.org/u/Dimitri)\
**Post date:** [September 17, 2021, 8:41pm UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712/3 "2021-09-17T20:41:35Z")

</div>

Hi @yrodiere.  
Awww, I was missing

```auto
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:

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

```

where DocumentIdBridge.java is as follows:

```auto
...
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:

```auto
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:

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

```

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

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [September 20, 2021, 7:34am UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712/4 "2021-09-20T07:34:12Z")

</div>

> [@Dimitri](#):
>
> 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 🙂

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.

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [September 23, 2021, 7:13am UTC](https://discourse.hibernate.org/t/hibernate-search-6-doesnt-support-bigdecimal-primary-keys/5712/5 "2021-09-23T07:13:03Z")

</div>

Split this topic on September 23, 2021, 7:13am UTC

2 posts were split to a new topic: [Changing the analyzer used by @FullTextField by default](https://discourse.hibernate.org/t/changing-the-analyzer-used-by-fulltextfield-by-default/5726)
