Issues

Select view

Select search mode

 
50 of

FetchNotFoundException after Upgrade to 6.6.X

Description

After an upgrade from 6.4.8.Final to 6.6.5.Final, there seems to be an issue with executing the following queries.
They still work as expected in 6.5.3.Final and stopped working from 6.6.0.Final onwards. The issue persists in 6.6.11.Final.

We receive the following exception when executing the test case:
org.hibernate.FetchNotFoundException: Entity 'custom.MyBEntity' with identifier value 'B1' does not exist

Reproducer:

package org.hibernate.bugs; import custom.MyAEntity; import custom.MyBEntity; import custom.MyCEntity; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.NonUniqueResultException; import jakarta.persistence.Persistence; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.List; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; /** * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API. */ class JPAUnitTestCase { private EntityManagerFactory entityManagerFactory; @BeforeEach void init() { entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" ); } @AfterEach void destroy() { entityManagerFactory.close(); } // Entities are auto-discovered, so just add them anywhere on class-path // Add your tests, using standard JUnit. @Test void testFetchNotFoundException() throws Exception { EntityManager entityManager = entityManagerFactory.createEntityManager(); // Given entityManager.getTransaction().begin(); var newB = new MyBEntity("B1", 1); var newC = new MyCEntity("C1"); entityManager.persist(newB); entityManager.persist(newC); entityManager.getTransaction().commit(); // When entityManager.getTransaction().begin(); getB(entityManager, "B1"); getAListForB(entityManager, "B1"); var newAEntity = new MyAEntity(); newAEntity.setId("A1"); newAEntity.setBId("B1"); newAEntity.setCId("C1"); entityManager.merge(newAEntity); // Then assertDoesNotThrow(() -> getAListForC(entityManager, "C1", 1)); entityManager.getTransaction().commit(); entityManager.close(); } private MyBEntity getB(EntityManager entityManager, String bId) { var query = entityManager.createQuery(""" SELECT b FROM MyBEntity b WHERE b.id = :id """, MyBEntity.class); query.setParameter("id", bId); var list = query.getResultList(); if (list == null || list.isEmpty()) return null; else if (list.size() > 1) throw new NonUniqueResultException(); else return list.get(0); } private List<MyAEntity> getAListForB(EntityManager entityManager, String bId) { var query = entityManager.createQuery(""" SELECT DISTINCT a FROM MyAEntity a JOIN a.c c JOIN a.b b where a.bId = :bId AND c.deletedOn IS NULL """, MyAEntity.class); query.setParameter("bId", bId); return query.getResultList(); } private List<MyAEntity> getAListForC(EntityManager entityManager, String cId, Integer someNumber) { var query = entityManager.createQuery(""" SELECT DISTINCT a FROM MyAEntity a JOIN FETCH a.c c JOIN FETCH a.b b where b.someNumber = :someNumber and a.cId = :cId """, MyAEntity.class); query.setParameter("cId", cId); query.setParameter("someNumber", someNumber); return query.getResultList(); } } @Getter @Setter @EqualsAndHashCode(of = {"id"}) @Entity public class MyAEntity { @Id @Column(name = "ID", nullable = false) private String id; @Column(name = "B_ID", nullable = false) private String bId; @Column(name = "C_ID", nullable = false) private String cId; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "B_ID", nullable = false, insertable = false, updatable = false) private MyBEntity b; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "C_ID", nullable = false, insertable = false, updatable = false) private MyCEntity c; } @Setter @Getter @Entity public class MyBEntity { @Id @Column(name = "ID", nullable = false) private String id; @Column(name = "SOME_NUMBER", nullable = false) private Integer someNumber; @Setter(AccessLevel.NONE) @OneToMany(mappedBy = "b", fetch = FetchType.LAZY) private List<MyAEntity> aList; public MyBEntity() {} public MyBEntity(String id, Integer someNumber) { this.id = id; this.someNumber = someNumber; } } @Setter @Getter @Entity public class MyCEntity { @Id @Column(name = "ID", nullable = false) private String id; @Column(name = "DELETED_ON") private Date deletedOn; @OneToMany(mappedBy = "c", fetch = FetchType.EAGER) private List<MyAEntity> aList; public MyCEntity() {} public MyCEntity(String id) { this.id = id; } }

 

See also the following post in the Hibernate forum: https://discourse.hibernate.org/t/fetchnotfoundexception-after-upgrade-to-6-6-x/11229

Details

Assignee

Reporter

Priority

Created 3 hours ago
Updated 3 hours ago

Activity

Show: