Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/Employee"

(GIT)
(Deploy and Try)
 
(38 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
This set of examples uses a common employee domain model and relational schema with various configuration approaches.
 
This set of examples uses a common employee domain model and relational schema with various configuration approaches.
 +
 
* '''Model''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file.
 
* '''Model''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file.
* '''Model No SQL''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file on a NoSql platform.
 
 
* '''Model Web''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.
 
* '''Model Web''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.
 
* '''Model Web JS''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.
 
* '''Model Web JS''': JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.
* '''Dynamic''': Dynamic persistence (no Java classes) mapped using API and eclipselink-orm.xml
 
  
 
== Try them Out ==
 
== Try them Out ==
  
To try out these examples you can download from the project's GIT repository or you can download the packaged projects.
+
To try out these examples using GIT, Maven, and the Eclipse Java EE IDE. These example projects can be adapted for other development environments.
  
=== GIT ===
+
=== Check out the code ===
  
You can check the latest versions of all the example projects out of GIT from [https://github.com/eclipse/examples git.eclipse.org]:
+
You can check the latest versions of all the example projects out of GIT from:
  
* git://git.eclipse.org/gitroot/eclipselink/examples.git
+
* Eclipse.org: [https://github.com/eclipse/examples git.eclipse.org/gitroot/eclipselink/examples.git] or browse the source [https://github.com/eclipse/examples/tree/master/jpa/employee here].
* ssh://git.eclipse.org/gitroot/eclipselink/examples.git
+
* GitHub: [https://github.com/eclipse/examples]
* http://git.eclipse.org/gitroot/eclipselink/examples.git
+
  
=== Download ===
+
=== Build and Test ===
  
== Understanding the Examples ==
+
The model project comes with test cases that validate the JPA model and its services function correctly. It is configured to run on embedded derby by default so generally running 'mvn test' in the model project will run the examples and test cases and let you know that everything is working correctly.
  
=== Employee Model ===
+
If using the model within Eclipse you can build using the right click context menu on the employee project.
  
The employee model has existed in TopLink and EclipseLink since the mid 90's. The model has evolved a little over the years based on enhancements made available in the mappings.
+
[[Image:buildit.jpg]]
  
[[Image:EclipseLink_Example_Employee_model.png]]
+
On the prompt window, click 'OK'
  
=== JPA 2.0 and Extended Features ===
+
[[Image:buildp1.jpg]]
  
When updated for EclipseLink 2.1 several JPA 2.0 features were introduced to the model and its mappings. These include:
+
On the next window, select the 'Update Snapshots' checkbox (to ensure you have the latest libraries) and click 'Run'
* PhoneNumber now mapped using derived identifiers so its primary key of EMP_ID and PTYPE are mapped with PhoneNumber.owner and PhoneNumber.type. The previous redundant mapping of PhoneNumber.id has been removed.
+
 
 +
[[Image:buildp2.jpg]]
 +
 
 +
Once the build has completed you should see the following 'SUCCESS' in the console window. Scrolling the console window you'll see test results of building, populating the database and some coded tests of the models. In your directory structure, the necessary jar and war files are created and ready to be deployed to your container.
 +
 
 +
[[Image:build-success.jpg]]
 +
 
 +
=== Setup your Container ===
 +
 
 +
* Requires a data source named 'java:global/employeeDS' which the user is required to set up.
 +
* It must be setup to use JTA transactions.
 +
 
 +
=== Deploy and Try ===
 +
 
 +
Within Eclipse, to deploy your application you may use the context menu to select 'Run On Server'.
 +
 
 +
[[Image:deploy.jpg]]
 +
 
 +
Note: When deploying your app from Eclipse, ensure under Server Properties that you set the Publishing Mode to '''"Publish as an exploded archive"'''.
 +
 
 +
Once the application is successfully deployed you can use the example within Eclipse.
 +
 
 +
[[Image:deployed.jpg]]
 +
 
 +
Alternatively you may also navigate to the homepage in your browser of choice (http://localhost:7001/employee.web/):
 +
 
 +
[[Image:homepage-medium.jpg]]
 +
 
 +
The first thing you'll want to do at this point is set up your database tables from the Admin page. You can also populate some test data from there as well:
 +
 
 +
[[Image:admin-medium.jpg]]
 +
 
 +
Now, you're ready to query (search) the database, add new employees and delete some as well.
 +
 
 +
Try this, from the home page where you can do a basic search, use the defaulted wildcard values to search for all the employees.
 +
 
 +
[[Image:search-medium.jpg]]
 +
 
 +
This should bring you the search results page.
 +
 
 +
[[Image:results-medium.jpg]]
 +
 
 +
From here you can edit or delete employees as needed. By clicking the Edit button this will present you a page where a number of changes can be made for a specific employee. Maybe someone needs a pay increase?! Once all necessary changes are made, click Save to update this employee on the database.
 +
 
 +
From the edit page you may also Delete employees, give it a shot!
 +
 
 +
[[Image:edit-medium.jpg]]
 +
 
 +
Lastly, why not create some new employees, the current group of minions aren't getting any younger ;-)
 +
 
 +
[[Image:create-medium.jpg]]
 +
 
 +
So there you have it in a nutshell. Play around with the app some more, try advance searching where you can use EclipseLink's pagination options etc.
 +
 
 +
== Understanding the Example ==
 +
 
 +
=== Employee Model ===
 +
 
 +
The employee model has existed in TopLink and EclipseLink since the mid 90's. The model has evolved a little over the years based on enhancements made available in the mappings. The following class diagram details the Employee model used in this example.
 +
 
 +
[[Image:EclipseLink_Example_Employee_model.png]]
  
While the majority of the Employee examples use pure JPA mappings several extensions offered by EclipseLink are highlgted including:
+
== Feedback ==
* <code>Employee.gender</code> mapped to the enum Gender using a converter to store a single char code in the database instead of the full enum's name or oridinal position.
+
  
=== Configuration Options ===
+
If you encounter any issues with the example, please let us know either through:
  
* Annotations
+
# [http://www.eclipse.org/forums/index.php?t=thread&frm_id=111 EclipseLink Forum]
* ORM XML
+
# [https://bugs.eclipse.org/bugs/ Bug Database]
** EclipseLink ORM
+
** JPA ORM + EclipseLink ORM
+

Latest revision as of 10:24, 23 May 2013

EclipseLink JPA Employee Examples

This set of examples uses a common employee domain model and relational schema with various configuration approaches.

  • Model: JPA using standard and extended annotations along with eclipselink-orm.xml mapping file.
  • Model Web: JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.
  • Model Web JS: JPA using standard and extended annotations along with eclipselink-orm.xml mapping file with a web interface.

Try them Out

To try out these examples using GIT, Maven, and the Eclipse Java EE IDE. These example projects can be adapted for other development environments.

Check out the code

You can check the latest versions of all the example projects out of GIT from:

Build and Test

The model project comes with test cases that validate the JPA model and its services function correctly. It is configured to run on embedded derby by default so generally running 'mvn test' in the model project will run the examples and test cases and let you know that everything is working correctly.

If using the model within Eclipse you can build using the right click context menu on the employee project.

Buildit.jpg

On the prompt window, click 'OK'

Buildp1.jpg

On the next window, select the 'Update Snapshots' checkbox (to ensure you have the latest libraries) and click 'Run'

Buildp2.jpg

Once the build has completed you should see the following 'SUCCESS' in the console window. Scrolling the console window you'll see test results of building, populating the database and some coded tests of the models. In your directory structure, the necessary jar and war files are created and ready to be deployed to your container.

Build-success.jpg

Setup your Container

  • Requires a data source named 'java:global/employeeDS' which the user is required to set up.
  • It must be setup to use JTA transactions.

Deploy and Try

Within Eclipse, to deploy your application you may use the context menu to select 'Run On Server'.

Deploy.jpg

Note: When deploying your app from Eclipse, ensure under Server Properties that you set the Publishing Mode to "Publish as an exploded archive".

Once the application is successfully deployed you can use the example within Eclipse.

Deployed.jpg

Alternatively you may also navigate to the homepage in your browser of choice (http://localhost:7001/employee.web/):

Homepage-medium.jpg

The first thing you'll want to do at this point is set up your database tables from the Admin page. You can also populate some test data from there as well:

Admin-medium.jpg

Now, you're ready to query (search) the database, add new employees and delete some as well.

Try this, from the home page where you can do a basic search, use the defaulted wildcard values to search for all the employees.

Search-medium.jpg

This should bring you the search results page.

Results-medium.jpg

From here you can edit or delete employees as needed. By clicking the Edit button this will present you a page where a number of changes can be made for a specific employee. Maybe someone needs a pay increase?! Once all necessary changes are made, click Save to update this employee on the database.

From the edit page you may also Delete employees, give it a shot!

Edit-medium.jpg

Lastly, why not create some new employees, the current group of minions aren't getting any younger ;-)

Create-medium.jpg

So there you have it in a nutshell. Play around with the app some more, try advance searching where you can use EclipseLink's pagination options etc.

Understanding the Example

Employee Model

The employee model has existed in TopLink and EclipseLink since the mid 90's. The model has evolved a little over the years based on enhancements made available in the mappings. The following class diagram details the Employee model used in this example.

EclipseLink Example Employee model.png

Feedback

If you encounter any issues with the example, please let us know either through:

  1. EclipseLink Forum
  2. Bug Database