Skip Headers

# Explicitly Deleting From the Database

Previous

Next

If there are cases where you have objects that will not be garbage collected through privately owned relationships (especially root objects in your object model), then you can explicitly tell TopLink to delete the row representing the object using the `deleteObject` API, as shown in Example: Explicitly Deleting.

Explicitly Deleting

    UnitOfWork uow = session.acquireUnitOfWork();
        pet petClone = (Pet)uow.readObject(Pet.class);
        uow.deleteObject(petClone);
    uow.commit();

The preceding code generates the following SQL:

    DELETE FROM PET WHERE (ID = 100)