Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Creating a Session (ELUG)

Elug draft icon.png For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/


For information on the various types of session available, see Session Types.

Each EclipseLink session is contained within a sessions configuration (sessions.xml) file. You can create a sessions configuration using the Workbench or Java code. We recommend that you use the workbench to create and manage your sessions (see Creating a Sessions Configuration).

Alternatively, you can create sessions in Java. For more information on creating sessions in Java, see EclipseLink API Reference.

After you create a session, you must configure its various options (see Configuring a Session). After configuring the session, you can use it in your application to manage persistence (see Acquiring and Using Sessions at Run Time).


Creating a Sessions Configuration

The Workbench lets you create session instances and save them in the sessions.xml file. These tools represent the sessions.xml file as a sessions configuration. Individual session instances are contained within the sessions configuration. You can create multiple sessions configurations, each corresponding to its own uniquely named sessions.xml file.

We recommend that you use the workbench to create and manage sessions. It is the most efficient and flexible approach to session management. For more information about the advantages of this approach, see Session Configuration and the sessions.xml File.

Workbench displays sessions configurations and their contents in the Navigator window. When you select a session configuration, its attributes are displayed in the Editor window.

The Sessions Configurations in Navigator Window figure calls out the following user interface elements:

  1. Sessions Configuration
  2. Database Session
  3. Relational Server Session
  4. Connection Pool
  5. EIS Server Session
  6. XML Session
  7. Session Broker


Sessions Configurations in Navigator Window

Sessions Configurations in Navigator Window


How to Create a Sessions Configuration Using Workbench

To create an EclipseLink sessions configuration (sessions.xml file), use this procedure:

  1. Click New New Project button on the toolbar and select Sessions Configuration.
    You can also create a new sessions configuration by selecting File > New > Session Configuration from the menu, or by clicking Create New Sessions Configuration New Sessions Configuration button in the standard toolbar.
  2. The new sessions configuration element appears in the Navigator window; the Sessions Configuration property sheet appears in the Editor window.
    Enter data in each field on the Sessions Configuration property sheet, as Configuring a Sessions Configuration describes.


Configuring a Sessions Configuration

Each EclipseLink sessions configuration (sessions.xml file) can contain multiple sessions and session brokers. In addition, you can specify a classpath for each sessions configuration that applies to all the sessions it contains.


How to Configure a Sessions Configuration Using Workbench

To configure a session configuration, use this procedure:

  1. Select the session configuration in the Navigator. Its properties appear in the Editor.
    Sessions Configuration Property Sheet
    Sessions Configuration Property Sheet

  2. Enter data in each field on the Sessions Configuration property sheet.


Use the following information to enter data in each field of the Sessions configuration property sheet:

Field Description
Project Save Location Click Change and select the directory in which to save the sessions configuration.
Classpath

Lists the JAR or ZIP files that contain the compiled Java classes on which this sessions configuration depends for features that require an external Java class (for example, session event listeners).

  • To add a JAR or ZIP file, click Add Entries or Browse add the file.
  • To remove a JAR or ZIP file, select the file and click Remove.
  • To change the order in which EclipseLink searches these JAR or ZIP files, select a file and click Up to move it forward or click Down to move it back in the list.
Sessions for sessions configuration name

Lists the available sessions defined in this sessions configuration:

  • To add a session, click Add Session.
  • To remove a session, select the session and click Remove.
  • To rename a session, select the session and click Rename.

For more information on creating sessions using Workbench, see the following:


See Also:

Configuring a Sessions Configuration


Creating a Server Session

We recommend that you create server sessions using the Workbench (see How to Create a Server Session Using Workbench).

After you create a server session, you create a client session by acquiring it from the server session (see Acquiring a Client Session).


How to Create a Server Session Using Workbench

Before you create a server session, you must first create a sessions configuration (see Creating a Sessions Configuration).

To create a new EclipseLink server session, use this procedure:

  1. Select the sessions configuration in the Navigator window in which you want to create a session.
  2. Click Add Session Add Session button on the toolbar. The Create New Session dialog box appears.
    You can also create a new server session by right-clicking the sessions configuration in the Navigator and selecting New > Session from the context menu, or by clicking Add Session on the Sessions Configuration property sheet.
    Create New Session Dialog Box, Server Session Option
    Create New Session Dialog Box, Server Session Option

  3. Enter data in each field on the Create New Session dialog box.


Use the following information to enter data in each field of the dialog box:

Field Description
Name Specify the name of the new session.
Use Server Platform

Check this field if you intend to deploy your application to a Java EE application server.

If you check this field, you must configure the target application server by selecting a Platform.

Platform

This option is only available if you check Use Server Platform.

Select the Java EE application server to which you will deploy your application.

EclipseLink supports the following Java EE application servers:

  • WebLogic 10.n
  • WebLogic 9.0
  • OC4J 10.1.3.n
  • SunAS 9.0
  • WebSphere 6.1
  • JBoss
  • Custom

The server platform you select is the default server platform for all sessions you create in this sessions configuration. At the session level, you can override this selection or specify a custom server platform class.

Select Data Source

Select the data source for this session configuration. Each session configuration must contain one data source. Choose one of the following:

  • Database to create a session for a relational project.
  • EIS to create a session for an EIS project.
  • XML to create a session for an XML project 1 .

See EclipseLink Project Types for more information.

Select Session Select Server Session to create a session for a single data source (including shared object cache and connection pools) for multiple clients in a three-tier application.


1 You cannot create a server session for an XML project.

How to Create a Server Session Using Java

You can create a server session in Java code using a project. You can create a project in Java code, or read a project from a project.xml file.

This example illustrates creating an instance (called serverSession) of a Server class using a Project class.


Creating a Server Session from a Project Class

 Project myProject = new Project();
 Server serverSession = myProject.createServerSession();

This example illustrates creating an instance (called serverSession) of a Server class using a Project read in from a project.xml file.

Creating a Server Session from a project.xml File Project

 Project myProject = XMLProjectReader.read("myproject.xml");
 Server serverSession = myProject.createServerSession();

This example illustrates creating a server session with a specified write connection pool minimum and maximum size (when using EclipseLink internal connection pooling). The default write connection pool minimum size is 5 and maximum size is 10.


Creating a Server Session with Custom Write Connection Pool Size

 XMLProjectReader.read("myproject.xml");
 Server serverSession = myProject.createServerSession(32, 32);


Creating Session Broker and Client Sessions

A session broker may contain both server sessions and database sessions. We recommend that you use the session broker with server sessions because server sessions are the most scalable session type.

We recommend that you create server sessions using the Workbench).

After you create and configure a session broker with server sessions, you can acquire a client session from the session broker at run time to provide a dedicated connection to all the data sources managed by the session broker for each client. For more information, see Acquiring a Client Session.


How to Create a Session Broker and Client Sessions Using Workbench

Before you create a session broker session, you must first create a sessions configuration (see Creating a Sessions Configuration) and one or more server sessions (see Creating a Server Session), or one or more database sessions (see Creating Database Sessions).

To create a new EclipseLink session broker, use this procedure:

  1. Select the sessions configuration in the Navigator window in which you want to create a session broker.
  2. Click Add Session Broker Add Session Broker button on the toolbar. The Create New Session Broker dialog box appears.
    You can also create a new session broker by right-clicking the sessions configuration in the Navigator window and selecting Add Session Broker from the context menu or by clicking Add Session Broker on the Sessions Configuration property sheet.
    Create New Session Broker Dialog Box
    Create New Session Broker Dialog Box

  3. Enter data in each field on the New Session Broker dialog box.

Use the following information to enter data in each field of the dialog box:

Field Description
Name Specify the name of the new session broker.
Use Server Platform

Check this field if you intend to deploy your application to a Java EE application server.

If you check this field, you must configure the target application server by selecting a Platform.

Platform

This option is available only if you check Use Server Platform.

Select the Java EE application server to which you will deploy your application.

EclipseLink supports the following Java EE application servers:

  • WebLogic 10.n
  • WebLogic 9.0
  • OC4J 10.1.3.n
  • SunAS 9.0
  • WebSphere 6.1
  • JBoss
  • Custom

The server platform you select is the default server platform for all sessions you create in this sessions configuration. At the session level, you can override this selection or specify a custom server platform class.

Select the sessions to Manage

Select sessions to be managed by this new session broker (from the list of available sessions) and click OK.

Note: This field appears only if the configuration contains valid sessions.


Continue with Configuring a Session.

See Also:

Creating Session Broker and Client Sessions
Configuring a Session

How to Create a Session Broker and Client Sessions Using Java

This example illustrates how you can create a session broker in Java code by instantiating a SessionBroker and registering the brokered sessions with it.

Because the session broker references other sessions, configure these sessions before instantiating the session broker. Add all required descriptors to the session, but do not initialize the descriptors or log the sessions. The session broker manages these issues when you instantiate it.


Creating a Session Broker

 Project databaseProject = new MyDatabaseProject();
 Server databaseSession = databaseProject.createServerSession();
 
 Project eisProject = new MyEISProject();
 Server eisSession = eisProject.createServerSession();
 
 SessionBroker sessionBroker = new SessionBroker();
 sessionBroker.registerSession("myDatabase", databaseSession);
 sessionBroker.registerSession("myEIS", eisSession);
 
 sessionBroker.login();


Creating Database Sessions

We recommend that you create database sessions using the Workbench (see How to Create Database Sessions Using Workbench).

After you create a database session, you can acquire and use it at run time. For more information on acquiring a database session, see Acquiring a Session from the Session Manager.


How to Create Database Sessions Using Workbench

Before you create a database session, you must first create a sessions configuration.

To create a new EclipseLink database session, use this procedure:

  1. Select the session configuration in the Navigator window in which you want to create a session.
  2. Click Add Session Add Session button. on the toolbar. The Create New Session dialog box appears.
    You can also create a new configuration by right-clicking the sessions configuration in the Navigator window and selecting New > Session from the context menu.
    Create New Session Dialog Box, Database Session Option
    Create New Session Dialog Box, Database Session Option

  3. Complete each field on the Create New Session dialog box.

Use the following information to enter data in each field of the dialog box:

Field Description
Name Specify the name of the new session.
Use Server Platform

Check this field if you intend to deploy your application to a Java EE application server.

If you check this field, you must configure the target application server by selecting a Platform.

Platform

This option is available only if you check Use Server Platform.

Select the Java EE application server to which you will deploy your application.

EclipseLink supports the following Java EE application servers:

  • WebLogic 10.n
  • WebLogic 9.0
  • OC4J 10.1.3.n
  • SunAS 9.0
  • WebSphere 6.1
  • JBoss
  • Custom

The server platform you select is the default server platform for all sessions you create in this sessions configuration. At the session level, you can override this selection or specify a custom server platform class.

Select Data Source

Select the data source for this session configuration. Each session configuration must contain one data source. Choose one of the following:

  • Database to create a session for a relational project.
  • EIS to create a session for an EIS project.
  • XML to create a session for an XML project.

See EclipseLink Project Types for more information.

Select Session Select Database Session to create a session for a single database (including shared object cache and connection pools) for a single client suitable for simple applications or prototyping.


Enter the necessary information and click OK.

Workbench window appears, showing the database session in the Navigator window.

Continue with Configuring a Session.

How to Create Database Sessions Using Java

You can create an instance of the DatabaseSession class in Java code using a Project. You can create a project in Java code or read a project from a project.xml file.

This example illustrates creating a DatabaseSession using a Project class.


Creating a Database Session from a Project Class

 Project myProject = new Project();
 DatabaseSession databaseSession = myProject.createDatabaseSession();

This example illustrates creating a DatabaseSession using a Project read in from a project.xml file.


Creating a Database Session from a project.xml File Project

 Project myProject = XMLProjectReader.read("myproject.xml");
 DatabaseSession databaseSession = myProject.createDatabaseSession();


Creating Remote Sessions

Remote sessions are acquired through a remote connection to their server-side session. Remote sessions are acquired through Java code on the remote client. The server-side session must also be registered with an org.eclipse.persistence.remote.ejb.RemoteSessionController and accessible from the RMI naming service.

You create remote sessions entirely in Java code.


How to Create Remote Sessions Using Java

The Server Creating RMIRemoteSessionController for Client and Client Acquiring RMIRemoteSessionController from Server examples demonstrate how to create a remote EclipseLink session on a client that communicates with a remote session controller on a server that uses RMI. After creating the connection, the client application uses the remote session as it does with any other EclipseLink session.


Server

The Server Creating RMIRemoteSessionController for Client example shows the code you add to your application's RMI service (MyRMIServerManagerImpl) to create and return an instance of an RMIRemoteSessionController to the client. The controller sits between the remote client and the local EclipseLink session.

The RMIRemoteSessionController you create on the server is based on an EclipseLink server session. You create and configure this server session as described in Creating a Server Session and Configuring Server Sessions.


Server Creating RMIRemoteSessionController for Client

 RMIRemoteSessionController controller = null;
 try {
     // Create instance of RMIRemoteSessionControllerDispatcher which implements
     // RMIRemoteSessionController. The constructor takes an EclipseLink session as a parameter
     controller = new RMIRemoteSessionControllerDispatcher (localEclipseLinkSession);
 } 
 catch (RemoteException exception) {
     System.out.println("Error in invocation " + exception.toString());
 }
 return controller;

Client

The client-side code gets a reference to the application's RMI service (in this example it is called MyRMIServerManager) and uses this code to get the RMIRemoteSessionController running on the server. The reference to the session controller is then used to create the RMIConnection from which it acquires a remote session.


Client Acquiring RMIRemoteSessionController from Server

 MyRMIServerManager serverManager = null;
 
 // Set the client security manager
 try {
     System.setSecurityManager(new MyRMISecurityManager());
 } 
 catch(Exception exception) {
     System.out.println("Security violation " + exception.toString());
 }
 // Get the remote factory object from the Registry
 try {
     serverManager = (MyRMIServerManager) Naming.lookup("SERVER-MANAGER");
 } 
 catch (Exception exception) {
     System.out.println("Lookup failed " + exception.toString());
 }
 
 // Start RMIRemoteSession on the server and create an RMIConnection
 RMIConnection rmiConnection = null;
 try {
     rmiConnection = new RMIConnection(serverManager.createRemoteSessionController());
 } 
 catch (RemoteException exception) {
     System.out.println("Error in invocation " + exception.toString());
 }
 
 // Create a remote session which we can use as a normal EclipseLink session
 Session session = rmiConnection.createRemoteSession();
 
</soure>
 
 
----
''[[EclipseLink User's Guide Copyright Statement|Copyright Statement]]''
 
 
[[Category: EclipseLink User's Guide]]
[[Category: Release 1]]
[[Category: Task]]

Back to the top