Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/ORMSessions

Sessions are a key component of the EclipseLink Server application— they provide EclipseLink with access to the database. Sessions enable you to execute queries, and they return persistent objects and other results for client applications.

See Using EclipseLink Sessions for complete information.


Session Manager

The EclipseLink session manager enables developers to build a series of sessions that are maintained under a single entity. The session manager is a static utility class that loads EclipseLink sessions from the sessions.xml file, caches the sessions by name in memory, and provides a single access point for EclipseLink sessions.

For specific examples, see:


Session Factory

Alternatively you may use the SessionFactory which is a Helper class to simplify the development and generation of code that accesses EclipseLink through the SessionManager (sessions config XML).

Responsibilities:

  • Lookup of a session by name using default or provided sessions config location
  • Support lookup of active UnitOfWork and Session in JTA environments
  • Hot/Re-deployment handling of applications
  • Detachment helpers to simplify usage within a local session bean


Create a Session Factory that uses the default sessions.xml file

SessionFactory sessionFactory = new SessionFactory("session-name");
Session sessionFactory.getSharedSession(); // By default this will log the session in.


Create a Session Factory that loads an alternative XML Configuration file

The alternative xml file name must be a resource path to the sessions configuration xml.

SessionFactory sessionFactory = new SessionFactory("app-session.xml", "session-name");
Session session = sessionFactory.getSharedSession(false, true); // Don't log the session in, but refresh it.

Back to the top