当前位置:   article > 正文

JPA多对多操作中,Lombok @DATA @EqualsAndHashCode循环依赖问题导致程序StackOverflowError_lombook 没有equalsandhash导致内存溢出

lombook 没有equalsandhash导致内存溢出

今天遇到的jpa出现内存溢出,并且在对集合转换时日志多条警告并且出现异常

错误
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@3f4d7874<rs=com.alibaba.druid.pool.DruidPooledResultSet@45d32798>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@2b391bf<rs=com.alibaba.druid.pool.DruidPooledResultSet@28b56317>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@8d93114<rs=com.alibaba.druid.pool.DruidPooledResultSet@6f1ee21d>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@2faf2ba6<rs=com.alibaba.druid.pool.DruidPooledResultSet@51ba061d>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@7b7568ff<rs=com.alibaba.druid.pool.DruidPooledResultSet@688e471f>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@65d52047<rs=com.alibaba.druid.pool.DruidPooledResultSet@4fdc4421>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@2445ec78<rs=com.alibaba.druid.pool.DruidPooledResultSet@3c79db27>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@7261114d<rs=com.alibaba.druid.pool.DruidPooledResultSet@d53e52b>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@2203bd6e<rs=com.alibaba.druid.pool.DruidPooledResultSet@668512ae>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@6e187671<rs=com.alibaba.druid.pool.DruidPooledResultSet@78b8933>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@65b561e6<rs=com.alibaba.druid.pool.DruidPooledResultSet@c3bfbb8>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@1f24ff64<rs=com.alibaba.druid.pool.DruidPooledResultSet@8b15bb8>
elAdmin- 2019-03-15 16:30:05 [http-nio-8000-exec-1] WARN  o.h.e.loading.internal.LoadContexts - HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@20f3d923<rs=com.alibaba.druid.pool.DruidPooledResultSet@138150ba>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
ERROR o.w.e.handler.GlobalExceptionHandler - org.wuyd.exception.BadRequestException: Failed to convert from type [java.util.ArrayList<?>] to type [java.util.Set<?>] for value '[Role{id=1, name='管理员', remark='系统所有权', createDateTime=2018-11-23 11:04:37.0}]'; nested exception is java.lang.StackOverflowError
  • 1

该问题是由于@EqualsAndHashCode 在role, permiss两个类中的

    @ManyToMany
    @JoinTable(name = "roles_permissions", joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "permission_id",referencedColumnName = "id")})
    private Set<Permission> permissions;

    @ManyToMany
    @JoinTable(name = "roles_menus", joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "id")})
    private Set<Menu> menus;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

@ManyTOMany 时 Lombok 生成的HashCode 会导致两个集合循环比较,造成内存溢出

解决方案是:
  • 自己手写hashcode 不要用lombok中的@Data和@hashcode
    Alt
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/650562
推荐阅读
相关标签
  

闽ICP备14008679号