Skip Headers

# Acquiring a Session at Run Time With the Session Manager

Previous

Next

The TopLink session manager enables developers to build a series of sessions that are maintained under a singleton object called the session manager.

The session manager is a static utility class that loads TopLink sessions from the `sessions.xml` file (see "Session Configuration and the sessions.xml File"), caches the sessions by name in memory, and provides a single access point for TopLink sessions.

At run time, TopLink will attempt to load the `sessions.xml` file from the two following default resource names: `sessions.xml` and `META-INF/sessions.xml`. Refer to Packaging a TopLink Application for additional information.

The session manager supports the following session types:

- `ServerSession` (see "Server and Client Sessions")

- `SessionBroker` (see "Session Broker and Client Sessions")

- `DatabaseSession` (see "Database Sessions")

The session manager has two main functions: it creates instances of these sessions and it ensures that only a single instance of each named session exists for any instance of a session manager.

The session manager instantiates sessions as follows:

1. The client application requests a session by name.

2. The session manager looks up the session name in the `sessions.xml` file. If the session name exists, the session manager instantiates the specified session; otherwise, it raises an exception.

3. After instantiation, the session remains viable until you shut down the application.

Once you have a session instance, you can use it to acquire additional types of sessions for special tasks. For example, you can acquire a unit of work from any session to perform transactional operations. You can acquire a client session from a server session to perform client operations in a three-tier architecture.

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