I am getting this error com.mysql.jdbc.PacketTooBigException and tracing through the code, it appears that it occurs on the following scenario (but only on tests)
public interface Students extends JpaRepository<Student, Integer> {
@EntityGraph("Student.withProgramAndSchedule")
@Query("from Student s")
Iterable<Student> findAllWithProgramAndSchedule();
}
@Entity
@NamedEntityGraph(
name = "Student.withProgramAndSchedule",
attributeNodes = {
@NamedAttributeNode("programEnrollments"),
@NamedAttributeNode("schedules")
}
)
public class Student implements Serializable {
...
}
Only during DataJpaTest it appears it does not clean up the Entity Manager context even when I had cleared the entity manager
@After
public void clearEntityManager() {
entityManager.clear();
}
Since this is with anonymized real data, it has thousands of records and what happens is it creates a query that looks like
select ... from ... where studentSchedule_0.id in (?, ?, ... thousands of ? later, ... ?)
Then it blows the 1MB packet limit.
So my question is (because I can't find it in the references) is it possible to limit the query size when it does the fetch with the IDs?