I have a Java Spring Boot application with the following entities related to the below exception
SProduct
@Entity
@Table(
name =
I Had This Problem When use Set, but When I do Change to List it's Solved You Should use
private List<FBT> fbts;
Firstly, it is a Hibernate Error handled by org.hibernate.engine
and has nothing to do with Spring Boot.
It can occur if you're fetching large amounts of data, like tens of thousands of entities with your HQL queries.
This can also be the case if you have mapped a one-to-many association which has many of child entities and due to bi-directional mapping the result-set is replicating infinitely.
Refer to link below for high performance JPA Tips.
https://vladmihalcea.com/14-high-performance-java-persistence-tips/
Can you try with @Fetch(value = SELECT)
?
@OneToMany(fetch = FetchType.EAGER, mappedBy = "mainProduct", cascade = CascadeType.ALL)
@Fetch(value=FetchMode.SELECT)
private Set<FBT> fbts;
In my case it was because of entities calling each other's hashcode recursively, if you use lombock remove it and make it yourself.Put breakpoint of debugger on the methods of two hashcodes. You'll sea that they are calling each other. Remove for example from the first entity's hashcode method second entity's link.
It seems like you are loading huge amount of data in your application.
The method
FBT findByMainProductAndCollection(SProduct mainProduct,Date collection);
will load all the matching data. But you only need count try the query that exactly return count of data instead of all the data.
One way to do is using the query you mentioned and other way is
Long countByMainProductAndCollection(SProduct mainProduct, Date collection);
Or
Boolean existsByMainProductAndCollection(SProduct mainProduct, Date collection)