6 Replies Latest reply: Jun 22, 2014 12:04 AM by Nina RSS

    View based on 2 entities - need to update only 1 entity

    Nina

      Hello,

       

      I have a view that based on 2 entities, only 1 is updateable.

      The select contains outer join on the updateable view.

      For example I have Departments and Employees with outer join on them (in the where clause) - some of the departments have no employees, but it still appear in the list.

      I don't have foreign keys between my tables on the db.

      I want to update the row by adding 1 employee .

      The creare method on the Employees entity is not invoked beacuse it is not a new row.

      The entity I want to update has some not null attributes and I don't know when and where to set them to default values (like id, date_updated...), even before updating the new employee in the department.

       

      Thank you,

      Nina

        • 1. Re: View based on 2 entities - need to update only 1 entity
          1000723

          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.

          • 2. Re: View based on 2 entities - need to update only 1 entity
            Nina

            Thank you,

            I still have a question...

            How is the new employee row created - is it done by the viewlink automatically or

            do I need to create new rows after executeQuery for each department row without employees?

             

            Thank you,

            Nina

            • 3. Re: View based on 2 entities - need to update only 1 entity
              1000723

              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();

              nvp.setAttribute("EmpName", theEmployeeName);

              nvp.setAttribute("EmpDob", theEmployeeDob);...

              //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.

              Regards.

              • 4. Re: View based on 2 entities - need to update only 1 entity
                Nina

                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.

                 

                Thank you,

                Nina

                • 5. Re: View based on 2 entities - need to update only 1 entity
                  1000723

                  Hi, did you find a solution?

                  • 6. Re: View based on 2 entities - need to update only 1 entity
                    Nina

                    Hi,

                    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!

                     

                    Thank you,

                    Nina