Skip Headers

# Storing Sessions in the Session Manager Instance

Previous

Next

Although Oracle recommends that you export all session instances from TopLink Workbench to one or more `sessions.xml` files, alternatively, you can manually create a session in your application and, as Example: Storing Sessions Manually in the Session Manager illustrates, manually store it in the session manager using `SessionManager` method `addSession`. Then, you can acquire a session by name using the `SessionManager` method `getSession`.

Note: The `addSession` method is not necessary if you are loading sessions from a session configuration file.

Storing Sessions Manually in the Session Manager

    // create and log in to the session programmatically
    Session theSession = project.createDatabaseSession();
    theSession.login();
    // store the session in the SessionManager instance
    SessionManager manager = SessionManager.getManager();
    manager.addSession("mysession", theSession);
    // retrieve the session
    Session session = SessionManager.getManager().getSession("mysession");