# How to resolve path to a persisted attribute in Hibernate ORM metadata

**URL:** <https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126>\
**Category:** Hibernate Search\
**Created:** [March 8, 2022, 1:53pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126 "2022-03-08T13:53:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 8, 2022, 1:53pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/1 "2022-03-08T13:53:00Z")

</div>

I am getting below exception at start up in hibernate-search 6

```auto
type 'com.xxxx.yyy.zzz..model.Link': failures: - HSEARCH800007: Unable to resolve path '.featureName' 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.

```

I have below code snippet something like this  
**Feature.java**

```auto
    @NaturalId(mutable = true)
    @Column(name = "feature_name", nullable = false)
    @NotNull
    @ApiModelProperty(required = true)
    @Size(min = 3, max = 50)
    @Pattern(regexp = "^[a-z0-9]+(-[a-z0-9]+)*$")
// @FullTextField
    @GenericField(sortable = Sortable.YES)
  // @Analyzer(definition = "lowercaseWhitespaceAnalyzer")
    private String featureName;

```

**Link.java**

```auto
  @JsonProperty("featureName")
        @FullTextField
    // @Analyzer(definition = "lowercaseWhitespaceAnalyzer")
        public String getFeatureName() {
            return feature != null ? feature.getFeatureName() : null;
        }

```

**Note:** 1)property is **not a transient** property and code was working fine in HS 5 with HS 5 annotations.  
2) it works if I add this annotation @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO) but I don’t want to stop auto indexing.

Is there any workaround for this issue?

---

<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 8, 2022, 2:20pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/2 "2022-03-08T14:20:45Z")

</div>

Again, this is documented in the migration guide: [Hibernate Search 6.0.11.Final: Migration Guide from 5.11](https://docs.jboss.org/hibernate/search/6.0/migration/html_single/#indexed-transient-requires-configuration)

> [@Prashant\_Kamble](#):
>
> property is **not a transient** property

`featureName` in entity `Link` is, as far as Hibernate ORM is concerned, a transient attribute. By this, I mean Hibernate ORM will not call `getFeatureName()` to retrieve the value and persist it in a dedicated column.

`Link#feature` is persisted, and `Feature#featureName` is persisted. But as far as Hibernate ORM knows, `Link#featureName` is not persisted. So it’s transient.

Now, in practice, `Link#featureName` is _derived_ from other persisted attributes: `Link#feature` and `Feature#featureName`. But without looking at the implementation of `Link#getFeatureName()`, Hibernate Search cannot know that. Which is why you need to give a hint with `@IndexingDependency(derivedFrom = ...)`:

```java
  @JsonProperty("featureName")
        @FullTextField
    // @Analyzer(definition = "lowercaseWhitespaceAnalyzer")
        @IndexingDependency(derivedFrom = @ObjectPath({ 
                @PropertyValue(propertyName = "feature"),
                @PropertyValue(propertyName = "featureName")
        }))
        public String getFeatureName() {
            return feature != null ? feature.getFeatureName() : null;
        }

```

> [@Prashant\_Kamble](#):
>
> and code was working fine in HS 5 with HS 5 annotations

Yes and no. Hibernate Search 5 may have booted without raising an exception, but:

1. Hibernate Search 5 was disabling some optimizations in an attempt to make this work, which could result in very bad performance in extreme scenarios.
2. If `Feature#featureName` was modified, Hibernate Search 5 would not detect the change and would not reindex the corresponding `Link` instance. Resulting in out-of-sync indexes.

See [Hibernate Search 6.0.11.Final: Migration Guide from 5.11](https://docs.jboss.org/hibernate/search/6.0/migration/html_single/#indexed-transient-requires-configuration)

---

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 8, 2022, 2:51pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/3 "2022-03-08T14:51:35Z")

</div>

> [@yrodiere](#):
>
> ```auto
> @IndexingDependency(derivedFrom = @ObjectPath( 
> @PropertyValue(propertyName = "feature"),
> @PropertyValue(propertyName = "featureName")
> ))
> 
> ```

Thanks for the detailed explaination @yrodiere .  
Just a question can we add multiple properties here? I mean entity name(“feature”) and property name(“featureName”)? I am getting compile time error '_=’ expected_  
Do I need to provide only entity name??

---

<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 8, 2022, 2:52pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/4 "2022-03-08T14:52:26Z")

</div>

> [@Prashant\_Kamble](#):
>
> Just a question can we add multiple properties here? I mean entity name(“feature”) and property name(“featureName”)? I am getting compile time error ’ _=’ expected_  
> Do I need to provide only entity name??

I don’t understand. Give me the actual code.

---

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 8, 2022, 2:59pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/5 "2022-03-08T14:59:18Z")

</div>

I have added similar code here in **Link.java** property like

```auto
    private Feature feature;
    @JsonProperty("featureName")
    @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
    @IndexingDependency(derivedFrom = @ObjectPath(
            @PropertyValue(propertyName = "feature"),
            @PropertyValue(propertyName = "featureName")
    ))
    public String getFeatureName() {
        return feature != null ? feature.getFeatureName() : null;
    }

```

---

<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 8, 2022, 3:00pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/6 "2022-03-08T15:00:30Z")

</div>

It’s a syntax error. Missing `{` and `}`.

> [@Prashant\_Kamble](#):
>
> ```auto
> private Feature feature;
> @JsonProperty("featureName")
> @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
> @IndexingDependency(derivedFrom = @ObjectPath({
> @PropertyValue(propertyName = "feature"),
> @PropertyValue(propertyName = "featureName")
> }))
> public String getFeatureName() {
> return feature != null ? feature.getFeatureName() : null;
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 8, 2022, 3:24pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/7 "2022-03-08T15:24:32Z")

</div>

Thanks @yrodiere exception gone away.  
what if we retrieve value from two diff entities based on conditions?? we need to include both the entities in @ObjectPath like below code snippet?

```auto
 @JsonProperty("teamName")
    @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
    @IndexingDependency(derivedFrom = @ObjectPath({
            @PropertyValue(propertyName = "feature"),
            @PropertyValue(propertyName = "team"),
            @PropertyValue(propertyName = "teamName")}
    ))
    public String getTeamName() {
        return feature != null ? feature.getTeamName() : team.getTeamName();
    }

```

```auto
 Here we used feature and team entity
```

---

<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 8, 2022, 3:26pm UTC](https://discourse.hibernate.org/t/how-to-resolve-path-to-a-persisted-attribute-in-hibernate-orm-metadata/6126/8 "2022-03-08T15:26:54Z")

</div>

No, in that case you’ll pass multiple ObjectPaths. `derivedFrom = { @ObjectPaths(...), @ObjectPaths(...) }`.
