I have a db table called Task. It has a structure like this:
taskid bigint(20) autoincrement identity
taskname varchar(255)
parentTaskId bigint(20)
The idea is to have a series of tasks just like MS Project. Some tasks can be subtasks of other parent tasks. The parentTaskId column will hold a reference to the TaskId from the parent row. When it comes to ORM, then I will have one to many and many to one relationships that refer to the same Entity.
I am trying to figure out how to implement this using Toplink Essentials - I found a Hibernate example that recommended something like this:
@Entity
private class Task{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long TaskId
@ManyToOne
private Task parentTaskId;
@OneToMany(mappedBy="parentTaskId")
private Collection<Task> subTasks;
}
I am missing a few pieces though - when I call a named native query to fetch Task objects, I want the parentTaskId property to be populated with a Task object, not just the id from the row. And if a task is a parent task, I would like the subTasks collection to be populated with all the Task objects that have their parentTaskId column set as that TaskId.
Could someone point me to an example of this using Toplink?