Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是什么导致Spring启动故障安全清理(收集)发生_Java_Mysql_Hibernate_Spring Boot - Fatal编程技术网

Java 是什么导致Spring启动故障安全清理(收集)发生

Java 是什么导致Spring启动故障安全清理(收集)发生,java,mysql,hibernate,spring-boot,Java,Mysql,Hibernate,Spring Boot,我有一个JavaSpring启动应用程序,其中包含与以下异常相关的以下实体 s产品 @Entity @Table( name = "product", indexes = @Index( name = "idx_asin", columnList = "asin", unique = true

我有一个JavaSpring启动应用程序,其中包含与以下异常相关的以下实体

s产品

@Entity
@Table(
        name = "product",
        indexes = @Index(
                name = "idx_asin",
                columnList = "asin",
                unique = true
        )
)
public class SProduct implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    @Column(name = "asin", unique = false, nullable = false, length = 10)
    private String asin;
    @Column(name = "rootcategory")
    private Long rootcategory;
    @Column(name = "imageCSV", unique = false, nullable = true, length = 350)
    private String imagesCSV;
    @Column(name = "title", unique = false, nullable = true, length = 350)
    private String title;
    private Date created;
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "mainProduct", cascade = CascadeType.ALL)
    private Set<FBT> fbts;
    @OneToOne(fetch = FetchType.EAGER, mappedBy = "downloadProductId", cascade = CascadeType.ALL)
    private Download download;
我的fbt存储库中有以下查询

  FBT findByMainProductAndCollection(SProduct mainProduct,Date collection);
当mainProduct和collection的数据库中存在数据时,导致以下消息输出异常,否则返回null

  <message>HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@69b7fcfc&lt;rs=HikariProxyResultSet@325408381 wrapping com.mysql.jdbc.JDBC42ResultSet@108693fa&gt;</message>
  <message>HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries</message>
  <message>HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@47c40535&lt;rs=HikariProxyResultSet@2005129089 wrapping com.mysql.jdbc.JDBC42ResultSet@9894f70&gt;</message>
  <message>HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries</message>
  <message>HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@5b0cd175&lt;rs=HikariProxyResultSet@1598144514 wrapping com.mysql.jdbc.JDBC42ResultSet@6a7ff475&gt;</message>
  <message>HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries</message>
  <message>HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@f67e2cc&lt;rs=HikariProxyResultSet@319200129 wrapping com.mysql.jdbc.JDBC42ResultSet@215b8a6&gt;</message>
  <message>HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries</message>
  <message>HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@5961afc0&lt;rs=HikariProxyResultSet@1772496904 wrapping com.mysql.jdbc.JDBC42ResultSet@5956a59b&gt;</message>
  <message>HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries</message>
  <message>HHH000100: Fail-safe cleanup (collections) : 
尽管这种情况类似,但在数据库中已经存在一个SProduct的数据库更新时,似乎也会随机发生

SProductRepo.saveAndFlush(s);
我说是随机的,因为11个运行相同代码的应用程序以随机间隔与上述消息一起退出。代码不会生成任何异常,10000次成功的数据库更新都是使用导致失败的相同代码进行的。当试图更新以前工作过的数据库时,代码停止

""2018-12-28 00:56:06 [KeepaAPI-RetryScheduler] WARN  org.hibernate.engine.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.eng
ine.loading.internal.CollectionLoadContext@5c414639<rs=HikariProxyResultSet@1241510017 wrapping Result set representing update count of 13>
""2018-12-28 00:56:06 [KeepaAPI-RetryScheduler] WARN  org.hibernate.engine.loading.internal.CollectionLoadContext - HHH000160: On CollectionLoadContext#cleanup, localLoa
dingCollectionKeys contained [1] entries
""2018-12-28 00:56:06 [KeepaAPI-RetryScheduler] WARN  org.hibernate.engine.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.eng
ine.loading.internal.CollectionLoadContext@5595c065<rs=HikariProxyResultSet@2140082434 wrapping Result set representing update count of 14>
""2018-12-28 00:56:06 [KeepaAPI-RetryScheduler] WARN  org.hibernate.engine.loading.internal.CollectionLoadContext - HHH000160: On CollectionLoadContext#cleanup, localLoa
dingCollectionKeys contained [1] entries
""2018-12-28 00:56:06 [KeepaAPI-RetryScheduler] WARN  org.hibernate.engine.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.eng
ine.loading.internal.CollectionLoadContext@2956fe24<rs=HikariProxyResultSe
我想知道的是,产生此类消息的一般原因是什么

为什么它们会停止我的应用程序,尽管我的插入语句是代码中最后执行的语句,它们周围有try-catch语句

是否有日志调试设置可用于确定生成消息的确切原因

有没有办法关闭或控制此功能

Pom

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
        <maven.test.skip>true</maven.test.skip>
    </properties>
    <repositories>
        <repository>
            <id>Keepa</id>
            <name>Keepa Repository</name>
            <url>https://keepa.com/maven/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-jetty</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-oauth2</artifactId>
            <version>v1-rev120-1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-java6</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-gmail</artifactId>
            <version>v1-rev48-1.22.0</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-nop</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
        </dependency>
        <dependency>
            <groupId>com.myjeeva.digitalocean</groupId>
            <artifactId>digitalocean-api-client</artifactId>
            <version>2.16</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.keepa.api</groupId>
            <artifactId>backend</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>org.jdeferred</groupId>
            <artifactId>jdeferred-core</artifactId>
            <version>1.2.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>22.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build

org.springframework.boot
spring启动程序父级
2.1.1.1发布
UTF-8
UTF-8
1.8
2.10
真的
基帕
基帕存储库
https://keepa.com/maven/
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧靴起动器
org.springframework.boot
spring启动程序日志记录
org.springframework.boot
spring-boot-starter-log4j2
org.springframework.boot
弹簧靴开发工具
运行时
org.springframework.boot
spring boot启动器集成
javax.mail
邮件
1.4.7
公地io
公地io
2.6
org.apache.commons
公用压缩
1.18
com.google.api-client
谷歌api客户端
1.22.0
com.google.oauth-client
谷歌oauth客户端jetty
1.22.0
com.google.api
google-api-services-oauth2
v1-rev120-1.22.0
com.google.oauth-client
google-oauth-client-java6
1.22.0
com.google.oauth-client
谷歌oauth客户端
1.22.0
com.google.api
谷歌api服务gmail
v1-rev48-1.22.0
org.codehaus.mojo
execmaven插件
1.5.0
org.slf4j
slf4j nop
com.jcraft
jsch
0.1.54
com.myjeeva.digitalocean
数字海洋api客户端
2.16
com.google.code.gson
格森
com.keepa.api
后端
最新的
org.jdeferred
jdeferredcore
1.2.6
番石榴
番石榴
22
mysql
mysql连接器java
运行时
org.springframework.boot
springbootmaven插件

看起来您正在应用程序中加载大量数据

方法

FBT findByMainProductAndCollection(SProduct mainProduct,Date collection);
将加载所有匹配的数据。但是您只需要count就可以尝试准确返回count数据而不是所有数据的查询

一种方法是使用您提到的查询,另一种方法是

Long countByMainProductAndCollection(SProduct mainProduct, Date collection);


首先,它是由
org.Hibernate.engine
处理的Hibernate错误,与Spring Boot无关

如果您正在获取大量数据,例如使用HQL查询获取数以万计的实体,则可能会发生这种情况

如果您映射了一个一对多关联,其中包含许多子实体,并且由于双向映射,结果集正在无限地复制,则也可能出现这种情况

有关高性能JPA提示,请参阅下面的链接


你能试试
@Fetch(value=SELECT)

@OneToMany(fetch=FetchType.EAGER,mappedBy=“mainProduct”,cascade=CascadeType.ALL)
@获取(值=获取模式。选择)
私人设置FBT;

在我的例子中,这是因为实体递归调用彼此的哈希代码,如果使用lombock,请将其删除并自行生成。将调试器的断点放在两个哈希代码的方法上。 你会发现他们在互相打电话。
例如,从第一个实体的hashcode方法中删除第二个实体的链接

我在使用Set时遇到了这个问题,但当我更改为List时,问题就解决了 你应该使用

  private List<FBT> fbts;
私有列表fbt;

在我的例子中,我使用了一个自动生成的
存储库
方法,该方法返回
列表
。事实证明,2000个实体对于Hibernate来说太多了。我修复了这个问题,将其替换为返回
Stream
,然后将实体映射到手工构建的结构
MyDataDetached

Try
existsByM
FBT findByMainProductAndCollection(SProduct mainProduct,Date collection);
Long countByMainProductAndCollection(SProduct mainProduct, Date collection);
Boolean existsByMainProductAndCollection(SProduct mainProduct, Date collection)
@OneToMany(fetch = FetchType.EAGER, mappedBy = "mainProduct", cascade = CascadeType.ALL)
@Fetch(value=FetchMode.SELECT)
private Set<FBT> fbts;
  private List<FBT> fbts;