This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I am a newbie to hibernate and am struck with the on-to-many usage. Consider this scenario: I have two tables department and employee and the relation between them is one-to-many.
department_id int primary key
department_name not null varchar(100)
employee_id int primary key
employee_name not nul varchar(100)
department_id int foreign key references department(department_id)
The data in the Department table is pre-defined as there will be fixed number of departments in any organization.
Now, I need to create new employee and assign them to a department. For this purpose, I created a jsp page with a text box for name and a drop down list pre-populated with departments. To insert the record, it was pretty straightforward. Using request.getParameter(), I retrieved the values of name and department and assigned them to the Employee object. Using the session.save(), I am able to save the object without using the one-to-many relationship and I suppose it has to be done that way only.
From the examples I found on the web for one-to-many relationship, the parent object is saved first and then the child object.
Now my question is : Should we use one-to-many relationship only when we need to store objects in both the tables?