Skip to main content
Jump to: navigation, search


< EclipseLink‎ | Examples
Revision as of 07:49, 27 June 2011 by (Talk | contribs) (Example Overview)

EclipseLink MySports Example

The MySports example is a simple web application which demonstrates several key features of

EclipseLink including:

  • EclipseLink JPA
    • @Multitenant(SINGLE_TABLE)
    • Extensible entities with @VirtualAccessMethods

Example Overview

The example includes 3 projects

  1. MySports: A Dynamic Web project which deploys the primary application exposing a JSF and JAX-RS (REST) front end.
  2. MySports Admin:
  3. MySports Tests: A Java project containing Junit tests that verify the functionality of

Install & Config

At present the example is only available through SVN access. When completed a ZIP download will be made available.

Basic Steps

  1. Prepare Prerequisites:
    1. GlassFish 3.1
    2. Eclipse Java EE with GlassFish adapter
  2. Configure Eclipse
    1. Requires a variable named 'eclispelink_2.3_jar' for the javaagent usage of the test project
    2. Ensure you have a GlassFish Server configured in the Java EE perspective
  3. Configure GlassFish
    1. EclipseLink 2.3 bundles installed in GlassFish
    2. A connection pool named 'jdbc/MySports' must be defined in the server
  4. Get the example's projects
    1. Import the projects
    2. Customize the file for your database
  5. Run The example
    1. Run the MySports AllTests launch target. This will create the database tables and prepare an initial population
    2. Run the MySports Admin application
    3. Run the MySports application

Example Details

MySports Domain (example.mysports.model)

The domain model is that of any arbitrary sports league. The intent is to build an application that captures the state of an arbitrary league and use it in a multitenant application where multiple leagues (tenants) can be hosted. The domain model is intentionally unaware of the potential support for multiple leagues and therefore only models entities that exist within an individual league.

Class/Interface Description
@Table(name = "mys_div")
@TenantDiscriminatorColumn(name = "LEAGUE_ID", contextProperty = LEAGUE_CONTEXT)
    @NamedQuery(name="Division.findAll", query="SELECT d FROM Division d ORDER BY",
                hints={@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE, value=HintValues.TRUE)}),
    @NamedQuery(name="Division.findByName", query="SELECT d FROM Division d WHERE = :NAME")
public class Division implements Extensible {
@Table(name = "mys_team")
@TenantDiscriminatorColumn(name = "LEAGUE_ID", contextProperty = LEAGUE_CONTEXT)
@NamedQuery(name="Team.findByDivisionAndName", query="SELECT t FROM Team t WHERE = :NAME AND = :DIV")
public class Team implements Extensible {
 * In the MySports demo a Player entity represents an individual member of a
 * team. The Player entity is both multitenant and extensible.
@Table(name = "mys_player")
@TenantDiscriminatorColumn(name = "LEAGUE_ID", contextProperty = LEAGUE_CONTEXT)
public class Player implements Extensible {
Extensible An application interface used to indicate extensible types and enable their use in the presentation tier. This interface is not required or used by EclipseLink.
Divisions A non-entity container class used for returning multiple divisions from a JAX-RS call to enable the MOXy marshalling into XML.


The persistence layer is the main purpose of this example application. The persistence layer makes use of application bootstrapped persistence contexts with support for an EntityManagerFactory and backing ServerSession (with Cache) per league (tenant). This all bootstrapped off of a single persistence-unit definition.

Runtime Architecture

Mysports persistence.png


The LeagueRepository is the primary persistence abstraction responsible for league (tenant) specific persistence access managing both JPA persistence units and the MOXy JAXBContext.

JPA Usage

MOXy (JAXB) Usage

The application makes use of EclipseLink MOXy to map its persistent entities into XML within the JAX-RS (RESTful) interface. The mapping is done using an eclipselink-oxm.xml mapping file instead of JAXB annotations.

Back to the top