# How to write predicate having equal filter with DiscriminatorValue

**URL:** <https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281>\
**Category:** Hibernate ORM\
**Created:** [March 28, 2024, 4:11pm UTC](https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281 "2024-03-28T16:11:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vshrivas](https://avatars.discourse-cdn.com/v4/letter/v/b2d939/32.png) [@vshrivas](https://discourse.hibernate.org/u/vshrivas)\
**Post date:** [March 28, 2024, 4:11pm UTC](https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281/1 "2024-03-28T16:11:31Z")

</div>

After upgrading to spring framework 6, hibernate 6.x. we are seeing an issue and not getting a proper solution for it.

Brief about the issue:  
We have 3 persistent entity,

1. DocumentBaseLite (using below annotation)  
`@DiscriminatorColumn(name = "ENT_TYPE", discriminatorType = DiscriminatorType.INTEGER, columnDefinition = "int")`

2. Document (using the below annotation)  
`@DiscriminatorValue(value="1")`

3. Project (using the below annotation)  
`@DiscriminatorValue(value="2")`

We are fetching from DocumentBaseLite and I want to filter the result using the discriminatorValue.

my old code -  
Predicate predicate = cb.equal(root.type(),  
persistentEntityClass); jpaCriteriaBuilder.addPredicate(predicate);

I am passing the persistentEntityClass as Document.class

Error faced : **HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Unrecognized entity name: com.pkg.service.s1.persistence.entity.Document**

Requirement - Please let us know, how to fix this?

Any workaround?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [March 28, 2024, 4:21pm UTC](https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281/2 "2024-03-28T16:21:14Z")

</div>

The error is pretty self explanatory: apparently the class `com.informatica.service.frs.persistence.entity.Document` is not an entity type. You can only compare an entity type to another entity type, so comparison validation is failing.

Is `Document` a mapped entity type? And is it a subclass of the entity that you’re trying to filter in your query? Maybe show the complete mappings of your inheritance hierarchy types that use discriminators.

---

<div class="post-metadata">

**Author:** ![vshrivas](https://avatars.discourse-cdn.com/v4/letter/v/b2d939/32.png) [@vshrivas](https://discourse.hibernate.org/u/vshrivas)\
**Post date:** [March 28, 2024, 4:58pm UTC](https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281/3 "2024-03-28T16:58:43Z")

</div>

```auto
@Entity
@DiscriminatorValue(value=FRSConstants.ENT_DOCUMENT_TYPE)
@EdmEntityMapping(entityType="Document", entitySet = "Documents", persistentEntity=Document.class)
public class Document extends DocumentBase {
}

```

Document is not a mapped entity class but its parent class is “DocumentBase”.

Tried to explain the relation using a diagram.  
 ![relation](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/3/3488a1a9868f2b1b20136f516e065190286685cc.png)

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [March 29, 2024, 8:06am UTC](https://discourse.hibernate.org/t/how-to-write-predicate-having-equal-filter-with-discriminatorvalue/9281/4 "2024-03-29T08:06:21Z")

</div>

You can’t compare any subclass of `DocumentBase` using the discriminator condition, the subtype itself must also be a mapped entity type. From the code excerpt you pasted here, though, it looks like the `Doument` class is annotated `@Entity` - I think bot that and `Project` should be part of your mappings.
