Skip Headers

# Writing All Objects to the Database With a Session Query

Previous

Next

You can call the `writeAllObjects()` method to write multiple objects to the database. The `writeAllObjects()` method performs the same does-exist check as the `writeObject()` method and then performs the appropriate insert or update operations.

Writing Several Objects Using writeAllObjects

    // Read a Vector of all the current employees in the database.
    Vector employees = (Vector) session.readAllObjects(Employee.class);
    ...// Modify any employee data as necessary
    // Create a new employee and add it to the list of employees
    Employee susan = new Employee();
    ...
    // Initialize the new instance of employee
    employees.add(susan);
    /* Write all employees to the database. The new instance of susan not currently in the database will be inserted. All the other employees currently stored in the database will be updated */
    session.writeAllObjects(employees);