I have two JPA Entity classes, Task and TaskList. There's a one-to-many relationship between TaskList and Task (obviously) with the tasklist_id
foreign key in the task
table.
The Task
class is this:
@Entity(name = "task")
public class Task implements Serializable {
// Id and 3 fields
@ManyToOne
@JoinColumn(name="tasklist_id")
private TaskList parentList;
// 3 more fields
// Constructor
public Task() {}
//Getters and Setters
}
and the TaskList
class is this:
@Entity(name = "task_list")
public class TaskList implements Serializable {
// Id and two fields
@OneToMany(mappedBy="parentList")
private List<Task> tasks;
// Constructor
public TaskList() {}
}
When I try to add an automatic getter and setter to these two classes and a toString() function, I get a StackOverflowError.
How do I go about writing getters and setters for the two fields so that I get a proper object with toString()
?