Why don't you create two views with a view link.
DepartmentVO (View object)
EmployeesVO (View object)
EmployeesByDepartmentVL (View link between DepartmentVO and EmployeesVO ).
And then you can create the new employee from the View that is the child of department view.
For the default values, it depends on how are you creating the new employee but a good method is to have it in the entity object: on the attribute (id) for example, set the default value to expression and set the expression to get the value from a db sequence for ex.
How are you creating the new employee?
If you are displaying a master/detail tables then use the employee table that is inside the department table (this will be available after you add it in the application module.) in the data control to create the detail table.
If you are creating the row programatically, you use the employees rowSetIterator from your department row for ex:
RowSetIterator empRS = (RowSetIterator)deptRow.getAttribute("EmployeesByDepartment");//EmployeesByDepartment is the name that you give when creating the //view link
NameValuePairs nvp = new NameValuePairs();
//No need to set the department id because it will be automatically set since you are getting the RowSetIterator corresponding of your department row.
So in both cases, the department id will be set automatically.
I need to show the user a table that contails all the departments with employees in them , and for empty departments to show a new row next to it, so the user can write the emplyee details without the need for him to add a row.
I mean that I need the row to be created when the query is executed.
I created 2 views with a view link between them.
There is no association because the second view is based on a sql query.
The query works fine, but I want to create empty rows after execute query, so the user dons't need to add a row when he wants to add an employee to an empty department.
I still don't understand how it should be done.
Do I need to have association between entities for it to work?
If you have an exanple that would be great!