Hi.. JavaRanch forum member I am having one problem in inserting data to my POJO having one to many relationship with each other.
I am using JPA persistence layer with spring and Ext JS 4.0.2a as a frontend technology
my Project pojo class is
my Task pojo class is
the relationship is like One project may have many Task.
the json data i am receiving on my server side is
as my id is unique and autoincreement so no need to pass id. But i am having problem with the insertion of this JSON data i am receiving as the Project primary key is associated in relation with Task.
I tried to assign the values with the below method
I tried to insert the Task with jsonTask but not able to assign task to POJO Task. When i removed the jsonTask all data in assigned to Project POJO.
So is there any way i can insert data to Project table of my database and Project's startDate, endDate,projectId will also be inserted to my Task table
Why not just create the Project and Task directly and assign the values instead of using toBean, especially since your data does not match anyway.
Ensure that you set both sides of the task relationships (set the task's project).
You may also try using EclipseLink Moxy which now support mappings objects to/from JSON data.
I am using Hibernate JPA as my ORM. I just want to know that first I have to insert all the data to my Project Table and then I have to select the Data available inside Project table and pass them to my Task Table.
My project table id will be the foreign key of the Task table projectId.
still no one to help me to come out of this problem.
I am not able to get how to solve this one to many relationship problem. I am able to insert the data in both of the table but the problem is that How do I insert the primary key of both tables to the third one
yes Vijitha Kumara, I am having one to many relationship between PROJECT 1------* TASK currently i am able to insert the records in both tables.
My Project table has fields id, name, title, startDate, endDate and Task table has fields id, depth, duration, durationUnit, startDate, endDate, parentId, percentDone, priority, taskIndex, taskName.
Now I want to establish one To many relation between Project and Task.
I take the input as project name, title, startDate, endDate. As soon as the project detail is entered I am also inserting the startDate and endDate to my Task table. And I am one to many relationship due to which third table is generated as project_task. But the problem is that project_task not able to hold the primary key's of project ID and task ID.
In my project pojo i am maintaining relationship with task with
Before look at your solution why you need a third table to manage a One-to-Many relationship? Can't you have the "Many" side (Task table in this case) keep the foreign key to hold the relationship as that is the normal way of handling this?