0

There was a problem with the implementation of the findAll () methods. When called, Deadlock occurs.

@Data
@Entity
@Table(name = "groups")
public class Group {
   /** other fields omitted **/
   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   private Faculty faculty;
 }

@Data
@Entity
@Table(name = "faculties")
public class Faculty {
   /** other fields omitted **/
   @OneToMany( cascade = CascadeType.ALL,
               orphanRemoval = true)
   private List<Group> groups = new ArrayList<>();
}

Repository:

@Repository
public interface FacultyRepository extends JpaRepository<Faculty, Long> {
}

@Repository
public interface GroupRepository extends JpaRepository<Group, Long> {
}

When I call the findAll () method from the controller,

the result is as follows

I installed all the dependencies between the objects as recommended here

Please tell me how to fix this Deadlock=) Thanks)

Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42
Oleg
  • 1
  • Relationships are not as recommended there. Attribute `mappedBy="faculty"` is missing from `@OneToMany`. – Mikko Maunu Feb 16 '20 at 16:46
  • @MikkoMaunu if set (Attribute mappedBy="faculty") - I get an exception – Oleg Feb 16 '20 at 16:53
  • You should avoid both side CascadeType.ALL – Oleksii Valuiskyi Feb 16 '20 at 16:55
  • @alexvaluiskui that is, i need to delete CascadeType.ALL in Group and Faculty?) just did it, the deadlock remained(( – Oleg Feb 16 '20 at 17:02
  • You question appears to have absoutely nothing to do with Soring Data, JPA or the database but with an error serializing to JSON, a question that has been asked and answered many times before. – Alan Hay Feb 17 '20 at 09:49
  • Does this answer your question? [Infinite Recursion with Jackson JSON and Hibernate JPA issue](https://stackoverflow.com/questions/3325387/infinite-recursion-with-jackson-json-and-hibernate-jpa-issue) – Alan Hay Feb 17 '20 at 09:50
  • Remove the mapped relationships from the equals and hashCode methods (@EqualsAndHasCode(exclude = {"faculty"}) on class declaration or @EqualsAndHashCode.Exclude on field declaration if using lombok) – Eduardo Meneses Feb 18 '20 at 15:06

0 Answers0