I have a webapp that has an object that contains a collection of itself. I am struggling with how to model this in a MySQL database. This is a Task object that contains a list of subtasks. This is what the class looks like:
Task.java
public class Task{
private int taskID;
private String name;
private String details;
private List<Task> subTasks
...other properties
public Task(int taskID, String name, String details){
this.taskID = taskID;
this.name = name;
this.details = details;
this.subTasks = new ArrayList<>();
}
Getters and Setters here...
}
After some research and thinking about it on my own, I came up with one possible solution. I have an image of a UML diagram, but I cannot post it since I just joined and my SO rep is not high enough yet. So I did my best to show it with the symbols below:
--------------------- -------------------
| Task | | SubTaskMap |
--------------------- 1 __∞_|-----------------
| int taskID |----|__∞_|int subTaskID |
| String taskName | |int parentTaskID |
| String taskDetail | -------------------
--------------------
, subTaskID parentTaskID SubTaskMap, taskID Task ( , Task Java). , , , parentTaskID , Task.
MS Access , parentTaskID, 5, Task.taskID SubTaskMap.subTaskID Task_Copy SubTaskMap, Task_copy.taskID SubTaskMap.parentTaskID SQL-, :
SELECT Task.taskName, SubTask.parentTaskID
FROM Task AS Task_Copy INNER JOIN (Task INNER JOIN SubTask ON Task.taskID = SubTask.subTaskID) ON Task_Copy.taskID = SubTask.parentTaskID
WHERE (((SubTask.parentTaskID)=5));
, ?
!