Skip Headers

# Using registerAllObjects

Previous

Next

The `registerAllObjects` method takes a `Collection` of objects as an argument and returns a `Collection` of clones. This lets you register many objects at once as shown in Example: Using registerAllObjects.

Note: You cannot use `UnitOfWork` methods `registerObject`, `registerNewObject`, or `registerExistingObject` with an aggregate object (see "Relational Aggregate Descriptors"). Doing so will raise a ValidationException or other errors at commit time. For more information, see "Working With Aggregates".

Using registerAllObjects

    UnitOfWork uow = session.acquireUnitOfWork();
        Collection toRegister = new Vector(2);
        VetVisit vv1 = new VetVisit();
        vv1.setId(70);
        vv1.setNotes("May have flu");
        vv1.setSymptoms("High temperature");
        toRegister.add(vv1);

        VetVisit vv2 = new VetVisit();
        vv2.setId(71);
        vv2.setNotes("May have flu");
        vv2.setSymptoms("Sick to stomach");
        toRegister.add(vv2);

        uow.registerAllObjects(toRegister);
    uow.commit();