What casuses Spring Boot Fail-safe cleanup (collections) to occur

前端 未结 5 2312
梦谈多话
梦谈多话 2021-02-20 14:35

I have a Java Spring Boot application with the following entities related to the below exception

SProduct

@Entity
@Table(
        name =         


        
相关标签:
5条回答
  • 2021-02-20 14:39

    I Had This Problem When use Set, but When I do Change to List it's Solved You Should use

      private List<FBT> fbts;
    
    0 讨论(0)
  • 2021-02-20 14:42

    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/

    0 讨论(0)
  • 2021-02-20 14:45

    Can you try with @Fetch(value = SELECT)?

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "mainProduct", cascade = CascadeType.ALL)
    @Fetch(value=FetchMode.SELECT)
    private Set<FBT> fbts;
    
    0 讨论(0)
  • 2021-02-20 14:47

    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.

    0 讨论(0)
  • 2021-02-20 15:00

    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)
    
    0 讨论(0)
提交回复
热议问题