# CriteriaBuilder.equal fails with Cannot compare left expression of type 'com.personal.persistence.entity.Hotel' with right expression of type 'java.lang.Integer'

**URL:** <https://discourse.hibernate.org/t/criteriabuilder-equal-fails-with-cannot-compare-left-expression-of-type-com-personal-persistence-entity-hotel-with-right-expression-of-type-java-lang-integer/10468>\
**Category:** Hibernate ORM\
**Created:** [October 17, 2024, 8:47am UTC](https://discourse.hibernate.org/t/criteriabuilder-equal-fails-with-cannot-compare-left-expression-of-type-com-personal-persistence-entity-hotel-with-right-expression-of-type-java-lang-integer/10468 "2024-10-17T08:47:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amberjoshi](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@amberjoshi](https://discourse.hibernate.org/u/amberjoshi)\
**Post date:** [October 17, 2024, 8:47am UTC](https://discourse.hibernate.org/t/criteriabuilder-equal-fails-with-cannot-compare-left-expression-of-type-com-personal-persistence-entity-hotel-with-right-expression-of-type-java-lang-integer/10468/1 "2024-10-17T08:47:44Z")

</div>

Hibernate-core 6.4.2, SpringBoot 3.2.10. I upgraded my Spring from 3.0.7 and Hibernate from 6.1.7. I am seeing this error. Not Sure if criteria api is compatible with these versions. Help.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2024, 3:05pm UTC](https://discourse.hibernate.org/t/criteriabuilder-equal-fails-with-cannot-compare-left-expression-of-type-com-personal-persistence-entity-hotel-with-right-expression-of-type-java-lang-integer/10468/2 "2024-10-17T15:05:07Z")

</div>

The error is pretty clear. You can’t compare an expression with the type `Hotel` with an expression of the type `Integer`. You probably have some code like `criteriaBuilder.equal( root.get( "hotel" ), id )` which is simply invalid. Use the primary foreign key `criteriaBuilder.equal( root.get( "hotel" ).get( "id" ), id )`.
