X

Shay Shmeltzer's Oracle Development Tools Tips

REST enable your Database for CRUD with TopLink/EclipseLink and JDeveloper

Shay Shmeltzer
Director of Product Management - Oracle

It seems that REST interfaces are all the rage now for accessing your backend data, this is especially true in the world of mobile development. In this blog I'm going to show you how easy it is to provide a complete REST interface for your database by leveraging TopLink/EclipseLink and JDeveloper.

This relies on a capability that is available in TopLink 12c where every JPA entity that you have created can be RESTified with a simple servlet that TopLink provides.

All you need to do is locate the file toplink-dataservices-web.jar on your machine (this is included in the JDeveloper install so you can just search that directory) and then package your project as a WAR.

At that point you'll be able to get a complete CRUD set of operation for this entity.

In the video below I'm to retrieving departments by their id using a URL like this:

http://127.0.0.1:7101/TLServices-Project1-context-root/persistence/v1.0/out/entity/Departments/30

(out - name of my persistence unit. Departments - name of my entity) 

A complete list of all the REST URL syntax is here part of the TopLink documentation on this feature.:

http://docs.oracle.com/middleware/1213/toplink/solutions/restful_jpa.htm#CHDEGJIG

Check out how easy the process is in this video (using MySQL database):

Here are some additional URL samples for getting other types of queries:

Get all the Employees -  http://127.0.0.1:7101/TLServices/persistence/v1.0/out/query/Employees.findAll

Get all the Employees in department 50 - http://127.0.0.1:7101/TLServices/persistence/v1.0/out/entity/Departments/50/employeesList

Executing a specific named query (@NamedQuery(name = "Employees.findByName", query = "select o from Employees o where o.first_name like :name order by o.last_name"))  -http://127.0.0.1:7101/TLServices/persistence/v1.0/out/query/Employees.findByName;name=John

Join the discussion

Comments ( 4 )
  • guest Thursday, November 20, 2014

    I followed these steps, but get a 404 page not found error when trying test the web service. I'm not sure how to determine which step went wrong, do you have any tips on how to debug this?


  • Shay Thursday, November 20, 2014

    guest - check to see if you get errors in the WebLogic log window. Otherwise it is likely that your URL path is not correctly formatted.

    Check your app context root and the names of your entities.


  • Alex Reichman Tuesday, February 16, 2016

    Thank you for sharing , great presentation.

    I was able to deploy to weblogic and retrieve the departments from my Oracle XE database but creating the connection to PostgreSQL I have tried different links ( query, metadata etc.) I am still getting

    "This XML file does not appear to have any style information associated with it. The document tree is shown below."

    Postgres table has 4000 records in it ( migrated from Oracle)

    I would appreciate any help

    Thanks


  • Alex Reichman Wednesday, February 17, 2016

    I was able to run URL against Postgresql after adding postresql jdbc driver to weblogic setDomainEnv.sh and configuring the data source to connect to the database.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.