- Introduction
- Out Of Scope
- Explanation EclipseLink
- Explanation EntityManager
- Explanation Database
- Explanation System Design
- Explanation Other important Points
- Technologies Used
- Prerequisities
- Contribution
- References
- Contact Information
This project contains an application for employee registration which uses JavaEE and uses EclipseLink to register information of the employee in the database. The main focus of the project is understand what EclipseLink is and how to use it within JavaEE eco system. The main emphasis is given on EntityManagerFactory and EntityManager interface as well as EntityTransaction and how to use it. For this purpose, a simple JPA Project is created.
Since the idea of this project is to understand EclipseLink and specifically how EntityManager works, front-end is ignored. Similarly, no tests are written.
Eclipselink builds high performance applications that store persistent object-oriented data in a relational database. It is used to design, implement, deploy and optimize an advanced object-persistant and object.transformation layer that supports a variety of data sources and formats, including the following:
- Relational ---- for transactional persistence of Java Objects to a relational database using JDBC
- Object-Relational data type ---- for transactional persistence of java objects to special purpose data source representations optimized for storage in object-relational data type databases such as Oracle Database, MySQL, Postgres, MS SQL Server etc.
- Enterprise information system (EIS) ---for transactional persistence of Java objects to a nonrelational data source accessed using a Java EE Connector architecture (JCA) adapter, and any supported EIS record type, including indexed, mapped, or XML.
- XML ---- for nontransactional, nonpersistent (in-memory) conversion between Java objects and XML Schema Document (XSD)-based XML documents using Java Architecture for XML Binding (JAXB).
The following diagram depicts the Eclipselink Runtime Architecture:
An entity manager is used to interact with the persistence context. An entity manager is used to read, delete and write an entity. The Entity Manager API is used
- to create and remove persistent entity instances,
- to find entities by their primary key, and
- to query over entities.
A Persistence Context is a setg of entity instances in which there is a unique entity instance for any persistent entity identity. Within the persistence context, the entity instance and their life cycles are managed.
The EntityTransaction interface is used to control transactions on resource-local entity managers. The EntityManager.getTransaction() method returns the EntityTransaction interface.
For database, MySql is used however, one can choose any other database. Since the focus is on understanding the Eclipselink in general and EntityManager in particular, one only table is created inside the database which keeps the records of the employees. The fields are: id, first name, last name, username, password, address and contact. The primary key is id.
CREATE TABLE `employees`.`employee` (
`id` int(3) NOT NULL,
`first_name` varchar(20) DEFAULT NULL,
`last_name` varchar(20) DEFAULT NULL,
`username` varchar(250) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
`address` varchar(45) DEFAULT NULL,
`contact` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
- com.umer.entity contains Employee.java class which is the entity implementation class for Entity: Employee.
- EmployeeService.java used for creating the EntityManagerFactory,EntityManager and EntityTransaction.
- persistence.xml acts as the glue between entity classes and the entity manager.
- entityManagerFactory.createEntityManager()--->create entity manager. entityManager.getTransaction()---> creates transaction. entityTransaction.begin() ---> begins the transaction, CRUD operations are performed. entityTransaction.commit() commits the transaction. entityManager.close()---> closes the entity manager.
<persistence-unit name="employee">
defined in persistence.xml is referenced in the EmployeeService class(i.e. PERSISTENCE_UNIT_NAME) when calling EntityManagerFactory.
-
jdbc.driver, jdbc.url, jdbc.user and jdbc.password are defined in persistence.xml.
-
This is a JPA Facet project. JPA version used is 2.1.
-
Problems with BuildPath: It may be that the project is not compiling correctly. In that case, please ensure that the Build path is correct. This is done by Opening Project -->build path --> Configure BuildPath --> module Path == Appropriate JRE System and ClassPath == custom Eclipselink libraries which are downloaded and loaded in the project.
- Java 11
- JavaEE: Java Platform, Enterprise Edition (Java EE) is the standard in community-driven enterprise software. Java EE is developed using the Java Community Process, with contributions from industry experts, commercial and open source organizations, Java User Groups, and countless individuals. Each release integrates new features that align with industry needs, improves application portability, and increases developer productivity.
- MySQL: MySQL is an open-source relational database management system (RDBMS) and MySQL has stand-alone clients that allow users to interact directly with a MySQL database using SQL, but more often, MySQL is used with other programs to implement applications that need relational database capability.
- EclipseLink: Comprehensive open-source Java persistence solution addressing relational, XML, and database web services.
- The database is already created with an employee table. If it is not present, please refer to the database section above to see how it can be organized.
Feature requests, issues, pull requests and questions are welcome.
- 1: JPA with Eclipse Link Implementation(Youtube)
- 2: "Could not find Main Class" Problem
- 3: Understanding EclipseLink, 3.0 (Official Documentation)
- 4: EclipseLink Solutions Guide for EclipseLink Release 3.0 (Official Documentation)
- 5: Jakarta Persistence API (JPA) Extensions Reference for EclipseLink, Release 3.0 (Official Documentation)
- 6: Developing JAXB Applications Using EclipseLink MOXy, Release 3.0 (Official Documentation)
- 7: Understanding EclipseLink, 3.0 (Official Documentation)
- 8: Developing Persistence Architectures Using EclipseLink Database Web Services Release 3.0 (Official Documentation)
- 9: This document demonstrates EclipseLink’s support for the JPA specification, specifically the usage of the EntityManager API (Official Documentation with examples)
- 10: Introduction to EclipseLink (ELUG)
- 11: Entity Manger (JavaDoc)
How to reach me? At github specific gmail account.