# AssertionFailure when using @IndexedEmbedded on subentity

**URL:** <https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567>\
**Category:** Hibernate Search\
**Created:** [November 17, 2023, 2:46pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567 "2023-11-17T14:46:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eni\_Torok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/eni_torok/32/1927_2.png) [@Eni\_Torok](https://discourse.hibernate.org/u/Eni_Torok)\
**Post date:** [November 17, 2023, 2:46pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/1 "2023-11-17T14:46:41Z")

</div>

Hello,  
we had the following code:

```auto
@Entity(name = "EntityA")
@Indexed
public class EntityA{
...
 @OneToMany
 @IndexedEmbedded(structure = ObjectStructure.NESTED)
 @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
 private List<EntityB> b;
}

```

and we changed our data model to

```auto
@Entity(name = "EntityA")
@Indexed
public class EntityA{
...
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "entityA")
@IndexedEmbedded(structure = ObjectStructure.NESTED)
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
 private EntityB entityB;
}

@Entity(name = "EntityB")
public class EntityB{
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "entity_a_reference", insertable = false, updatable = false)
    private EntityA entityA;
}

```

since this change we are getting the following error:

```auto
org.hibernate.search.util.common.AssertionFailure: Attempted to detect entity type of object [] because a contained entity was modified, but this object does not seem to be an entity. -- this may indicate a bug or a missing test in Hibernate Search. Please report it: https://hibernate.org/community/

```

I am basically clueless… Could you please help me?

Thank you in advence!

---

<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:** [November 17, 2023, 2:50pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/2 "2023-11-17T14:50:27Z")

</div>

Hello,

This could be a bug in Hibernate Search, or an invalid mapping in Hibernate ORM. Not sure with the provided information.

Please:

- Format your code correctly so that we can read it all, putting a line with three backticks before and after the code:

````auto
```
code
```

````

- Format your stacktrace correctly, same idea:

````auto
```
stacktrace
```

````

- Provide the relevant mapping of `EntityB`, in particular the inverse side of the association
- Provide the full stack trace

EDIT: BTW you’re asking on a Friday afternoon, so… be prepared to only get an actual answer on Tuesday (busy on Monday). Sorry ☹

---

<div class="post-metadata">

**Author:** ![Eni\_Torok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/eni_torok/32/1927_2.png) [@Eni\_Torok](https://discourse.hibernate.org/u/Eni_Torok)\
**Post date:** [November 17, 2023, 3:24pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/3 "2023-11-17T15:24:54Z")

</div>

no problem at all, i also did not expect from you to investigate it right now, i just thought might be an obvious tiny problem that I have overseen. Code is now formatted but I can not insert a stack trace because it is too long, here is a screenshot instead.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/3/37b4848febf70f06675b7ad09f638117cec8423b.png)

---

<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:** [November 17, 2023, 3:29pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/4 "2023-11-17T15:29:28Z")

</div>

I don’t see an `@Entity` on `EntityA`, is that an oversight? Are you using XML mapping, maybe?

I think I’ll really need the whole relevant mapping to investigate. So, `EntityA`, `EntityB`, and all associations between them, in both ways.

---

<div class="post-metadata">

**Author:** ![Eni\_Torok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/eni_torok/32/1927_2.png) [@Eni\_Torok](https://discourse.hibernate.org/u/Eni_Torok)\
**Post date:** [November 17, 2023, 3:43pm UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/5 "2023-11-17T15:43:02Z")

</div>

Updated, thanks in advance! Have a nice weekend!

---

<div class="post-metadata">

**Author:** ![Eni\_Torok](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/eni_torok/32/1927_2.png) [@Eni\_Torok](https://discourse.hibernate.org/u/Eni_Torok)\
**Post date:** [November 21, 2023, 9:06am UTC](https://discourse.hibernate.org/t/assertionfailure-when-using-indexedembedded-on-subentity/8567/6 "2023-11-21T09:06:55Z")

</div>

Problem solved, it was indeed a mapping problem, we had also in the parent of EntityB a column named entity\_a\_reference - I removed that of course and also had to remove insertable = false, updatable = false , works like this

```auto
@Entity(name = "EntityA")
@Indexed
public class EntityA{
...
@OneToOne(fcascade = CascadeType.ALL, mappedBy = "entityA")
@IndexedEmbedded
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
 private EntityB entityB;
}

@Entity(name = "EntityB")
public class EntityB{
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "entity_a_reference")
    private EntityA entityA;
}

```
