what is the best way to insert an object in one-to-many ?
for example, one Employee has many Task.
Code:
Employee{
List<Task> taskList;
}
when we add one Task into Employee taskList, we have to load employee and its ALL task, and then save
Code:
function save_one_task(new_task){
Employee employee = dao.load(...);
List<Task> taskList = dao.loadAllTask(); // line 2
taskList.add(new_task);
employee.setTaskList(taskList);
dao.save(employee);
}
The major performance issue is line 2. we need to load ALL task, maybe 1000, just for adding ONE task.
Do we have a better way to resolve this issue ?
Thanks.