Skip Headers

# Loading a Session From sessions.xml Using Defaults

Previous

Next

If you have a single sessions configuration file (`sessions.xml`) that contains all the session instances created from by TopLink Workbench, then you can load a session by name, as Example: Acquiring a Named Session from Session Manager Using Defaults illustrates.

Acquiring a Named Session from Session Manager Using Defaults

    /* Load a named session (mysession) defined in the sessions.xml file. */
    SessionManager manager = SessionManager.getManager();
    Session session = manager.getSession("mysession");

In this example, the following session manager default configuration applies:

- Class loader–The thread-based class loader is used to find and load the `sessions.xml` resource and resolve any classes referenced in the `sessions.xml` and `project.xml` files.

  If you acquire the session in an application class, this will typically be the application's class loader, which is correct. In a J2EE application, it is best to specify this as the class loader from a class in the same JAR file that the `sessions.xml` file is deployed in.

- File–By default, the file named `sessions.xml` in the root directory relative to the class loader is used.

  If the file is named differently, or not in the root directory, the relative path must be specified. Relative resource paths in Java must use `/`, not `\`.

- Session name–The name passed into the `getSession` call.

  This name must be unique for the entire application server, not just unique within the application.

- Login–`true`. The session will be connected by default.

  If you must manually configure the session before login, set this option to `false` (see "Loading a Session Without Logging In").

- Refresh–`false`. If already loaded, the same session will be returned.

  Refresh should only be used, if it is known that the existing session is not being used, and the configuration has changed, such as in a J2EE environment redeployment scenario.

- Verify class loader–false. The session manager will not refresh the session if the class loader changes.

  This should normally be set to `true`. It must be set to `true` in a J2EE environment, if hot deployment or redeployment to a running application server is required (see "Refreshing a Session When the Class Loader Changes").