JPA: java.lang.StackOverflowError on adding toString method in entity classes
JPA: java.lang.StackOverflowError on adding toString method in entity classes Entity Class Teacher have toString() problem: @Entity public class Teacher { @Id @GeneratedValue ( strategy = GenerationType . AUTO ) private Long id ; private String name ; @OneToMany ( mappedBy = "teacher" , cascade ={ CascadeType . PERSIST }) private Set < Student > students = new HashSet < Student >(); public Teacher () {} public Teacher ( String name ) { this . name = name ; } public Set < Student > getStudents () { return students ; } public void addStudent ( Student student ) { students . add ( student ); student . setTeacher ( this ); } @Override public String toString () { return "Teacher[id=" + id + ", name=" + name + "]" ; } }