RESTful Web Service in JDeveloper 12c

Because the REST (Representational State Transfer) is lightweight, simple and flexible, many developers are building and exploring the RESTful Web Services, making it very popular, nowadays. According Roy Fielding, REST is an “architectural style” that basically exploits the existing technology and protocols of the Web. RESTful is typically used to refer to web services implementing the REST architecture.

In this post, you will learn how to build a RESTful Web Service using JDeveloper 12c (12.1.3). Download the sample application:

Create a Custom Application.
Set the Application Name as JDevRESTApp, Application Package Prefix as, and click Next.
Name the Project as Model, select EJB and Java as Project Features and click Next.
Change the Default Package to and click Finish.

Create the Employees Entity.
In the Applications window, right-click Model Project and choose New > From Gallery.
In the New Gallery dialog, choose Business Tier > EJB > Entities from Tables, and click OK.
In the Step 2 of Create Entities from Tables dialog, click Next.


In the Step 3, click Next.


In the Step 4, select database connection and click Next.


In the Step 5, select Employees Table and click Next.


In the Step 6, click Next.


In the Step 7, click Finish.


Open the file and perform the following steps:

  • Annotate the class with @XmlRootElement.
  • I think there is some bug when JDev generates entities from table, because SALARY property is not annotated. Annotate it with @Column(name = “SALARY”).
  • Annotate the employeesList and employees properties with @XmlTransient. Annotate the getEmployeesList and getEmployees accessors too.


Create the Employees Session Bean.
In the Applications window, right-click Model Project and choose New > From Gallery.
In the New Gallery dialog, choose Business Tier > Session Bean, and click OK.
In the Create Session Bean dialog, change the EJB Name to EmployeesService, and click Next.


Uncheck all methods, and click Finish.


Add the following methods to EmployeesService, EmployeesServiceBean and EmployeesServiceLocal.

public Employees persistEmployee(Employees employee) {
  return employee;

public Employees mergeEmployee(Employees employee) {
  Employees currentEmployee = getEmployee(employee.getEmployeeId());
  if (employee.getEmail() != null) 
  if (employee.getFirstName() != null)
  if (employee.getLastName() != null)
  if (employee.getHireDate() != null)
  if (employee.getJobId() != null)
  if (employee.getPhoneNumber() != null)
  if (employee.getSalary() != null)
  if (employee.getCommissionPct() != null)
  return em.merge(currentEmployee);

public void removeEmployee(Employees employee) {
  employee = em.find(Employees.class, employee.getEmployeeId());

public List getEmployees() {
  return em.createNamedQuery("Employees.findAll", Employees.class).getResultList();

public Employees getEmployee(Integer employeeId) {
  if (employeeId != null) {
    return em.find(Employees.class, employeeId);
  return null;

Create a REST Web Service Project.
In the Step 1, click Next.
In the Step 2, change the Default Package to and click Finish.
Double-click the WebService Project, add Model Project as Dependent Project, and click OK.


Create the Employees RESTful Service.
In the Applications window, right-click Rest Project and choose New > From Gallery.
In the New Gallery dialog, choose General > Java Class, and click OK.
In the Create Java Class dialog, change the Name to EmployeesResource and click OK.
Copy the following code inside your class:

public class EmployeesResource {

  EmployeesServiceLocal employeesService;

  public EmployeesResource() {

  public void create(Employees employee) {

  public void update(Employees employee) {

  public void delete(int id) {
    Employees employee = getById(id);
    if (null != employee) {

  public Employees getById(int id) {
    return employeesService.getEmployee(id);

  public List findAll() {
    return employeesService.getEmployees();

In the Applications window, right-click EmployeesResource class and choose Create RESTful Service.
Choose JAX-RS 2.0 Style and click Next.
Configure the RESTful Service and click Finish.


In the Return Type Warning dialog, click OK.


This is the result!


To test the RESTful Service, right-click class EmployeesResource and choose Test Web Service.
You may test each service operation using HTTP Analyzer.



8 replies on “RESTful Web Service in JDeveloper 12c”

“right-click file and choose Create RESTful Service.”
“To test the RESTful Service, right-click file and choose Test Web Service.”

shouldn’t both be “” ?

Thank you so much for the post.
Could you please explain how to deploy this application on standalone weblogic server?
We want the service URLs to be used in some other MAF applications.

Hi Saurabh!
You will need to create a WAR Deployment Profile for your WebService Project and an EAR Deployment Profile for your JDevRESTApp application.
Double-click WebService Project, go to Deployment and create a new WAR Deployment Profile. Use default settings.
In the main menu, choose Application > Application Properties. Go to Deployment and create a new EAR Deployment Profile.
In the Edit EAR Deployment Profile Properties dialog, go to Application Assembly, expand WebService.jpr node and mark the WAR Deployment Profile.
Right-click JDevRESTApp application and choose Deploy > .
You can deploy directly to a standalone weblogic server or generate an EAR file.

Let me know if it helped you.

Hi Waslley,

I have a doubt, when u create the , and – the two classes are interface and only is the implementation class. So the implementation will only be copied in and other two will have only reference to the methods (correct me if I am wrong).


The last line of the method:
mergeEmployee(Employees employee)
return em.merge(employee);
should be:
return em.merge(currentEmployee);

Comments are closed.