Entity not found exception though the entity do exist

Hi, I am working on a spring boot project where we use hibernate for orm and we use query dsl framework on top for querying data from the database.

Spring boot version: org.springframework.boot:spring-boot-starter-data-jpa:2.6.1
Hibernate version: org.hibernate:hibernate-core:5.6.1.Final

I have two tables,

  1. ContactMapping
    Columns - ID(PK), NAME
  2. Reports
    Columns - ID(PK), DATA, CONTACT_ID (FK) References ContactMapping

If I use CONTACT_ID as JoinColumn with ManyToOne and JoinColumn annotations then I am getting an “entity not found exception” while fetching data from the Reports table.
Otherwise, if I use it as a normal column with simple @Column annotation then I won’t be getting any exceptions.

What could be the reason for this scenario?

FYI,

Message: javax.persistence.EntityNotFoundException: Unable to find com.jungle.app.entity.room.RoomContactMapping with id 101

Trace:

javax.persistence.EntityNotFoundException: Unable to find com.jungle.app.entity.room.RoomContactMapping with id 101
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl.java:177)
	at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:216)
	at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:327)
	at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108)
	at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74)
	at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:118)
	at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1240)
	at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1105)
	at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:699)
	at org.hibernate.type.EntityType.resolve(EntityType.java:464)
	at org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:240)
	at org.hibernate.engine.internal.TwoPhaseLoad$EntityResolver.lambda$static$0(TwoPhaseLoad.java:576)
	at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntityEntryLoadedState(TwoPhaseLoad.java:221)
	at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:155)
	at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
	at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1201)
	at org.hibernate.loader.Loader.processResultSet(Loader.java:1009)
	at org.hibernate.loader.Loader.doQuery(Loader.java:967)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:357)
	at org.hibernate.loader.Loader.doList(Loader.java:2868)
	at org.hibernate.loader.Loader.doList(Loader.java:2850)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
	at org.hibernate.loader.Loader.list(Loader.java:2677)
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:540)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1468)
	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
	at org.hibernate.query.Query.getResultList(Query.java:165)
	at com.querydsl.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:191)
	at com.querydsl.jpa.impl.AbstractJPAQuery.fetch(AbstractJPAQuery.java:243)

Note: I am not using lazy fetch type in ManyToOne

First of all, I would suggest you to update to the latest version. Chances are, there might have been a bug which was fixed in a newer version already.
Also, are you sure you have a foreign key defined? If you do, then I am out of ideas and you’d have to provide us a reproducer for this problem, based on our test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java).