# @IndexingDependency for abstract Method

**URL:** <https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996>\
**Category:** Hibernate Search\
**Created:** [February 1, 2021, 8:20am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996 "2021-02-01T08:20:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Muller](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/peter_muller/32/1095_2.png) [@Peter\_Muller](https://discourse.hibernate.org/u/Peter_Muller)\
**Post date:** [February 1, 2021, 8:20am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/1 "2021-02-01T08:20:53Z")

</div>

Are abstract methods supported with @IndexingDependency? This is not documented in the docs and leads to no error:

```java
@Indexed
//(...)
public abstact class A {
    @Transient
    @GenericField
    public abstract String value();
} 

```

```java
@Indexed
//(...)
public class I1 extends A {
    @Transient
    @IndexingDependency(derivedFrom = {
            @ObjectPath(@PropertyValue(propertyName = "<someotherfield>"))
    })
    public abstract String value();
} 

```

```java
@Indexed
//(...)
public class I2 extends A {
    @Transient
    @IndexingDependency(derivedFrom = {
            @ObjectPath(@PropertyValue(propertyName = "<someotherfield>"))
    })
    public abstract String value();
} 

```

Of course for the abstract methods to make sense, queries for value are expected to work on `abstract class A`, `class I1` and `class I2` (haven’t come to test it yet -.- sorry).

---

<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:** [February 1, 2021, 8:24am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/2 "2021-02-01T08:24:24Z")

</div>

They’re not “supported” in the sense that we don’t have a specific test for this, but considering the way Hibernate Search is implemented, I’d expect this to work. Give it a try?

---

<div class="post-metadata">

**Author:** ![Peter\_Muller](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/peter_muller/32/1095_2.png) [@Peter\_Muller](https://discourse.hibernate.org/u/Peter_Muller)\
**Post date:** [February 1, 2021, 8:25am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/3 "2021-02-01T08:25:55Z")

</div>

Yep, I’m gonna try it and report back. It would be such a cool feature if it works.

---

<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:** [February 1, 2021, 8:37am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/4 "2021-02-01T08:37:03Z")

</div>

On a side note, while it may work with the model you gave in your post, it probably won’t work if another entity index-embeds `A.value`.

I suspect that a `@IndexedEmbedded A a` in another entity will lead to Hibernate Search not figuring out that `A.value` is derived and throwing an exception. That’s mostly because we [don’t support runtime polymorphism on `@IndexedEmbedded`](https://hibernate.atlassian.net/browse/HSEARCH-438), so we need all the metadata to be present on the type targeted by `@IndexedEmbedded` (in this case, `A`). Fixing this would not be trivial, unfortunately.

---

<div class="post-metadata">

**Author:** ![Peter\_Muller](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/peter_muller/32/1095_2.png) [@Peter\_Muller](https://discourse.hibernate.org/u/Peter_Muller)\
**Post date:** [February 5, 2021, 7:12am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/5 "2021-02-05T07:12:17Z")

</div>

I think the @IndexedEmbedded might work because all the metadata for the index should be present with the abstract method?

```auto
public abstact class A {
    @GenericField
    public abstract String value();

```

I’m not asking Hibernate Seach to pick up any new possible fields of I1 or I2 (like the additional childName of [[HSEARCH-438] Support runtime polymorphism on associations (instead of defining the indexed properties based on the returned type) - Hibernate JIRA](https://hibernate.atlassian.net/browse/HSEARCH-438)), but just the ones i explictly require in the base class.

Im going to try that once i have my model complete and can run some searches.

Edit: Tested it and currently does not work: Just as yrodiere said, once the abstract class is used in @IndexedEmbedded Hibernate Search again wants to check it and is not able to discover all derivedFroms.

The error is:

```auto
    Hibernate ORM mapping: 
        type 'I1': 
            failures: 
              - HSEARCH800007: Unable to resolve path '.value' to a persisted attribute in Hibernate ORM metadata. If this path points to a transient attribute, use @IndexingDependency(derivedFrom = ...) to specify which persisted attributes it is derived from. See the reference documentation for more information.
        type 'I2': 
            failures: 
              - HSEARCH800007: Unable to resolve path '.value' to a persisted attribute in Hibernate ORM metadata. If this path points to a transient attribute, use @IndexingDependency(derivedFrom = ...) to specify which persisted attributes it is derived from. See the reference documentation for more information.

```

---

<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:** [February 5, 2021, 7:41am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/6 "2021-02-05T07:41:49Z")

</div>

I agree `@IndexedEmbedded` could theoretically be made to work without solving HSEARCH-438, I’m just saying currently it probably won’t. I think changes would be needed.

I opened [HSEARCH-4148](https://hibernate.atlassian.net/browse/HSEARCH-4148) to address that, but I don’t know when we’ll have time to do it.

---

<div class="post-metadata">

**Author:** ![Peter\_Muller](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/peter_muller/32/1095_2.png) [@Peter\_Muller](https://discourse.hibernate.org/u/Peter_Muller)\
**Post date:** [February 5, 2021, 8:10am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/7 "2021-02-05T08:10:10Z")

</div>

Thanks for even looking at it! Through the issue finally I know where the Mapping Tests are 😄 [hibernate-search/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search at master · hibernate/hibernate-search · GitHub](https://github.com/hibernate/hibernate-search/tree/master/integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search)

---

<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:** [March 12, 2021, 12:23pm UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/8 "2021-03-12T12:23:25Z")

</div>

FYI, support for polymorphic `@IndexingDependency` should land in 6.1: [HSEARCH-4148 Polymorphic "derivedFrom" definition for derived properties by yrodiere · Pull Request #2525 · hibernate/hibernate-search · GitHub](https://github.com/hibernate/hibernate-search/pull/2525)

---

<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:40am UTC](https://discourse.hibernate.org/t/indexingdependency-for-abstract-method/4996/9 "2021-09-23T07:40:45Z")

</div>

Support for polymorphic `@IndexingDependency` is there:

> **[Hibernate Search 6.1.0.Alpha1 is out, now with asynchronous, distributed...](https://in.relation.to/2021/09/10/hibernate-search-6-1-0-Alpha1/#other-changes)**
>
> We just published Hibernate Search 6.1.0.Alpha1,
> an alpha release of the next minor version of Hibernate Search.
> 
> 
> 
> The main feature of this new version
> is a new concept of "coordination" to perform automatic indexing in an asynchronous, distributed...
