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

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

(Deploy and Try)
(Deploy and Try)
Line 35: Line 35:
 
Note: When deploying your app from Eclipse, ensure under Server Properties that you set the Publishing Mode to '''"Publish as an exploded archive"'''.
 
Note: When deploying your app from Eclipse, ensure under Server Properties that you set the Publishing Mode to '''"Publish as an exploded archive"'''.
  
[[Image:homepage.jpg]]
+
[[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:
 
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.jpg]]
+
[[Image:admin-medium.jpg]]
  
 
Now, you're ready to query (search) the database, add new employees and delete some as well.
 
Now, you're ready to query (search) the database, add new employees and delete some as well.
Line 45: Line 45:
 
Try this, from the home page where you can do a basic search, use the defaulted wildcard values to search for all the employees.
 
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.jpg]]
+
[[Image:search-medium.jpg]]
  
 
This should bring you the search results page.
 
This should bring you the search results page.
  
[[Image:results.jpg]]
+
[[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 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.
Line 55: Line 55:
 
From the edit page you may also Delete employees, give it a shot!
 
From the edit page you may also Delete employees, give it a shot!
  
[[Image:edit.jpg]]
+
[[Image:edit-medium.jpg]]
  
 
Lastly, why not create some new employees, the current group of minions aren't getting any younger ;-)
 
Lastly, why not create some new employees, the current group of minions aren't getting any younger ;-)
  
[[Image:create.jpg]]
+
[[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.
 
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.

Revision as of 12:53, 17 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.

Setup your Container

  • Requires a data source named 'java:global/employeeDS' which the user is required to set up.
  • Convenience scripts to do this are provided under employee.model\src\config\weblogic.
    • Usage example: createDataSource.cmd C:\Oracle\Middleware\wlserver_12.1

Deploy and Try

Once the application is successfully deployed you can navigate to the homepage in your browser (http://localhost:7001/employee.web/):

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

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.

EclipseLink Example Employee model.png

JPA 2.0 and Extended Features

When updated for EclipseLink 2.1 several JPA 2.0 features were introduced to the model and its mappings. These include:

  • 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.

While the majority of the Employee examples use pure JPA mappings several extensions offered by EclipseLink are highlgted including:

  • Employee.gender 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.

Back to the top