Skip Headers

# Create, Update, and Delete Object Session Queries

Previous

Next

Oracle recommends that you create and update objects using a unit of work: doing so is the most efficient way to manage transactions, concurrency, and referential constraints. For more information, see "Understanding TopLink Transactions".

However, you can also create and update objects using a session query. These session queries are a convenient way to modify objects directly on the database when you manage simple, nonbusiness object data that has no relationships (for example, user preferences).

If you know an object is new, you can use an `insertObject` method to avoid having TopLink perform an existence check. If you do not know if an object is new, use the `updateObject`, `writeObject`, or `writeAllObject` methods: TopLink performs an existence check if necessary.

When you execute a write session query, it writes both the object and its privately owned parts to the database. To manage this behavior, use a corresponding `DatabaseQuery` (see "Object-Level Modify Queries and Privately Owned Parts").

Using the `Session` method `deleteObject`, you can delete a specific object. Using the Session method `deleteAllObjects`, you can delete a collection of objects. Each specified object and all its privately owned parts are deleted. In the case of `deleteAllObjects`, all deletions are performed within a single transaction.

For more information, see "Creating, Updating, and Deleting Objects With a Session Query".