Skip Headers

# Providing Write Access

Previous

Next

Because the client session disables all database modification methods, a client session cannot create, change, or delete objects directly. Instead, the client must obtain a unit of work from the client session to perform database modification methods.

To write to the database, the client acquires a client session from the server session and then acquires a unit of work within that client session. The unit of work acts as an exclusive transactional object space, and also ensures that any changes that are committed to the database also occur in the session cache.

Note: Although client sessions are thread-safe, do not use them to write across multiple threads. Multithread write operations from the same client session can result in errors and a loss of data. For more information, see "Concurrency".

Figure: Writing with Client Sessions and Server Sessions illustrates how to write to the database using a client session acquired from a server session.

Writing with Client Sessions and Server Sessions

Description of "Writing with Client Sessions and Server Sessions"

To write to the database using a unit of work, use this procedure:

1. Acquire a session from the server session:

       Server server =
           (Server) SessionManager.getManager().getSession(
               sessionName, MyServerSession.class.getClassLoader()
           );
       Session clientSession = (Session) server.acquireClientSession();

   For more information, see "Acquiring and Using Sessions at Run Time".

2. Acquire a `UnitOfWork` object from the `Session` object.

       UnitOfWork uow = clientSession.acquireUnitOfWork();

   For more information, see "Unit of Work Sessions".

3. Use the unit of work to perform the required updates and then commit the `UnitOfWork`.

   For more information, see the following:

   - "Understanding TopLink Queries"

   - "Understanding TopLink Expressions")

   - "Understanding TopLink Transactions"