Tuesday, January 13, 2009

Create PL/SQL Webservice in JDeveloper 11g and eclipselink

In Late 2007 I already made a blog about creating a webservice in JDeveloper 11g TP based on a plsql package. Too bad the plsql web service creation option didn't make it in the final release of 11g. Maybe in the next release of 11g the plsql webservice will make a comeback. But creating a plsql webservice in the first jdeveloper 11g release is still possible. We will use eclipselink and some smart jdeveloper wizards to create this web service. This way of creating a web service gives you a lot of options how this plsql web service is created.

This is the pl/sql package I will use in this example. The package contains a current time funtion and a procedure which returns all the dept records of the scott scherma. Add this package to the scott schema

create or replace package scott_ws is

TYPE cursor_type IS REF CURSOR;

function get_current_time(date_format varchar2) return varchar2;

procedure get_all_department(dept_recordset OUT scott_ws.cursor_type);

end scott_ws;

create or replace package body scott_ws is

function get_current_time(date_format varchar2) return varchar2 is
v_time varchar2(20);
if date_format is null then
return 'empty format';
end if;
select to_char(sysdate, date_format) into v_time from dual;
return v_time;

when others then
return 'error';

procedure get_all_department(dept_recordset OUT scott_ws.cursor_type) is
OPEN dept_recordset FOR SELECT * FROM dept;
end get_all_department;

end scott_ws;

Now we can create a new TopLink project

We will use the eclipselink provider and use or create the scott database connection
JDeveloper creates a new project with a Toplink project file and a session xml. Open this xml where we use the default profile and select the Login link.
If you want to use a datasource then select managed datasource option and provide the datasource name ( this datasource has to be created in WebLogic )

Next we can create a session bean which wil contain the code which make a connection to the database using the default profile of the session xml and the eclipselink code for our plsql procedure / function

Give this bean a name and use the default values.

Implement a remote and local interface on the session bean

The next option is only necessary when we want to map the dept record to a dept java class. So the web services can use this class to transform these departments to xml.
Select the java objects from tables option in the TopLink/JPA category

Use the scott connection again

Select the dept table

The dept class looks like this.

package wsscott.definitions;


import java.math.BigDecimal;

* ### Generated by Oracle JDeveloper 11g - Mon Jan 12 23:08:08 CET 2009. ###

public class Dept implements Serializable {

private BigDecimal deptno;
private String dname;
private String loc;

public Dept() {

public Dept(BigDecimal deptno, String dname, String loc) {
this.dname = dname;
this.deptno = deptno;
this.loc = loc;

public BigDecimal getDeptno() {
return this.deptno;

public String getDname() {
return this.dname;

public String getLoc() {
return this.loc;

public void setDeptno(BigDecimal deptno) {
this.deptno = deptno;

public void setDname(String dname) {
this.dname = dname;

public void setLoc(String loc) {
this.loc = loc;


Here an overview of the toplink project.

Open your sessionbean class and add the following code to this bean

This code is necessary to create a connection to the database. In the sessions.xml file and in the default profile is our scott database connection or datasource defined

public class ScottSessionEJBBean implements ScottSessionEJB,
ScottSessionEJBLocal {

private SessionFactory sessionFactory;

// constructor
public ScottSessionEJBBean() {
this.sessionFactory = new SessionFactory("META-INF/sessions.xml", "default");

Here the code for the get_current function. See the eclipselink wiki for more plsql examples. Because we are calling an function we need to use StoredFunctionCall

public String plsqlCurrentTime(String format) {
StoredFunctionCall functionCall = new StoredFunctionCall();

// function name in package
// input parameter name
// function result datatype
functionCall.setResult("FUNCTION_RESULT", String.class);

ValueReadQuery query = new ValueReadQuery();
query.addArgument("date_format"); // input

// create an argument list and add a value for the date_format
List args = new ArrayList();

// get an database session
Session session = sessionFactory.getSharedSession();

// execute function and return the result
return (String)session.executeQuery(query, args);

The java code for the procedure is a bit more complex then the function. This methods return a list of dept classes.

public List plsqlDeptFindAll() {

// create a database session
Session session = sessionFactory.getSharedSession();

StoredProcedureCall spcall = new StoredProcedureCall();
// this procedure has only one output parameter

// make a new list of departments classes
List department = new ArrayList();
// execute the procedure.
List list = session.executeSelectingCall(spcall);

// make an iterator of the ref cursor result
ListIterator litr = ((List)list).listIterator();
while(litr.hasNext()) {

// when a the iterator has a next value then create
// a new dept class and fill its attributes
Dept dept = new Dept();
DatabaseRecord record =;
dept.setDeptno( (BigDecimal)record.get("DEPTNO") );
dept.setDname( (String)record.get("DNAME") );
dept.setLoc( (String)record.get("LOC") );
return department;

Add these two plsql methods to the remote and local ejb interface. After this we can select the EJB session bean and create a new web service

Choose a web service deployment profile

Give this web service a name
Just select our two plsql methods

The wizard will also create a new web service deployment. Use this deployment profile to deploy your ejb web service to WebLogic
When the deployment is successfull then we can take a look in the weblogic console. Go to deployments tab and open you enterprise application.

Select your Web Service to see the wsdl.

That's all, just generate a web service proxy to test this web service.
Here is the 11g project code.


  1. I followed exactly the instructions, but when I test whe web service, I get the error (rigth click on - test web service) in both methods:

    faultcode S:Server
    faultstring java.lang.NullPointerException

    Do you have any idea?

    my system:
    Windows xp
    Jdeveloper Studio Edition Version
    Build JDEVADF_MAIN.BOXER_GENERIC_081203.1854.5188
    Database Oracle 10g

  2. Hi where do you get this error.

    I know that if you try to test the ws in wls then this is a know bug.


  3. Hi Edwin,

    Can we able to deploy the PL/SQL webservices in weblogic server9.2?

    Is that possible to deploy the existing OAS PL/SQL webservices in weblogic server9.2?

    If so do we need any migration steps ?


  4. Hi,

    if your ws services are based on jax-rpc then it should work ,maybe you have to change the datasource name.

    ws made in jdev 11g uses jax-ws I don't think this work.

    good luck

  5. Hi Edwin,

    Our jdeveloper version is and weblogic server version is 9.2.

    I have installed BPEL PM in Weblogic server9.2.

    I tried to devlop & deploy the PL/SQL webservice in jdeveloper using JAX- RPC method. but i am not able to deploy.

    I am getting "NoclassDefFoundError WS_importjava/WsexchangeRtCollTypeIn" error while we deploy the PL/SQL ws in weblogic server 9.2.

    I have raised the SR also. But no use. Oracle answer is " We cannot able to deploy PL/SQL webservices in Weblogic server9.2".

    If you succeded in deploying the Pl/SQL webservices in weblogic server, please let me know the steps.


  6. Ok,

    I will give it a try to run a plsql ws on wls 10.3. I don't have wls 9.2


  7. Hi,

    I Developed a plsql webservice with jdev and made an war/ear.

    I deployed this on the wls 10.3 of jdeveloper 11g. It deploys perfectly

    now I generate a ws proxy client in to test this ws,

    and it works perfectly


  8. Hi Edwin,

    Thanks and do we need any other special steps?


  9. Hi,

    No special steps are needed. Just develop in make a ear of your ws and deploy this on a wls 10.3 with or without the ADF runtime installed ( I didn't test this with a default wls 10.3 ).


  10. Then i tried to call
    return (String)session.executeQuery(query,args);
    i've got
    "Error(100,33): method executeQuery(oracle.toplink.queryframework.ReadAllQuery, java.util.List) not found in interface org.eclipse.persistence.sessions.Session"

    The same result i've got using ReadAllQuery;
    Could you help me?

  11. Hi,

    Did you add a new method to the session bean. Then you need to do this also in your local or remote sessionbean interface.

    In the ejb client you are using the the remote or local interface.

    thanks Edwin

  12. Hi Edwin,
    Im trying to create web service from PL/SQL package and deploy it to Weblogic Server 10g. But im not able to create PL/SQL web server in Jdeveloper 11g( its giving SQL Exception. But this works perfectly in JDev10g on OC4J.

  13. Hi Arun,

    Can you give me more details about the error. I developed a plsql ws in and made a war and deployed this on wls server with ADF libs.
    It works perfectly


  14. Hi Edwin,

    This is the error im getting.

    Redeploying Application...
    [Deployer:149034]An exception occurred for task [Deployer:149026]deploy application /PL_SQL_WS-GetEmployee-context-root on DefaultServer.: [HTTP:101216]Servlet: "EmpWebServiceSoapHttpPort" failed to preload on startup in Web application: "PL_SQL_WS-GetEmployee-context-root.war".
    java.sql.SQLException: Error looking up <--java:comp/env/jdbc/hrconnDS-->:
    at hrconn.EmpWebServiceBase.<--init-->(
    at hrconn.EmpWebServiceUser.<--init-->(
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
    at java.lang.reflect.Constructor.newInstance(

  15. Hi Edwin,

    It worked finally. Its the data source config which I didnt make in Weblogic. Since in JDev 10g with OC4J the datasources are created by default.


  16. Thanks for this! I tried it already

  17. Hi,

    there is great news with Jdeveloper "The PL/SQL Web Services wizard that was removed from the JDeveloper 11g (Boxer) release due to incompatibilities with the WLS server have been fully restored."

    best regards,

  18. Hi Andreas,

    Thanks for the tip. I downloaded the latest Jdeveloper (JDEVADF_11. The PLSQL Web Service wizard is certainly back and fairly easy to use. However I was unable to create a successful project.

    The Wizard generation exits with the following error:
    WSDL and Mapping file generation failed for the following reason.

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at oracle.jdeveloper.webservices.Assembler$2$1.invoke(
    at $Proxy35.createWSDL(Unknown Source)
    at oracle.jdeveloper.webservices.model.plsql.generator.CreateWSDL.generateWSDL(
    at oracle.jdeveloper.webservices.model.plsql.generator.CreateWSDL.createWSDL(
    at oracle.jdeveloper.webservices.model.generator.CommonCreateWSDL.action(

  19. Hi Edwin,

    Your Blog Rocks! Literally you help a ton of people here.

    We have one question. We need to kick off an 11g composite from PL/SQL. We can kick it off but not get a response back using the PL/SQL package UTL_HTTP.

    Any ideas or code examples on how we could do this?


  20. Hi,

    is your soa 11g service a synchronous web service, if not then I can explain your problem, I don't think you can call a asyn web service from the db ( maybe with dbms_ws )

    thanks Edwin

  21. I meet error as following when testing webservice.

    '409 HTTP Analyzer Conflict'

    Have you met before?

  22. Hi,

    Did you have the http analyzer of jdev between the test and ws.

    if so disable the http analyzer or use soapui. a great free tool


  23. Need help on the exception below. Appreciate your help.


    Hi All,

    I have created the Custom SOA Object using the Iparser.
    Now i am trying to provide the grant through the SOA repository.
    When I click create,the its failing
    I am getting the following error when I click a CREATE GRANT button for a web service that has been deployed.

    Exception Details.
    oracle.apps.fnd.framework.OAException: oracle.jbo.NoDefException: JBO-25058: Definition isOverloaded of type Attribute not found in AdminMethodsVO
    at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(
    at oracle.apps.fnd.framework.webui.OAPageBean.renderDocument(
    at oracle.apps.fnd.framework.webui.OAPageBean.renderDocument(
    at _OA._jspService(
    at com.orionserver.http.OrionHttpJspPage.service(
    at oracle.jsp.runtimev2.JspPageTable.service(
    at oracle.jsp.runtimev2.JspServlet.internalService(
    at oracle.jsp.runtimev2.JspServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at com.evermind.server.http.ServletRequestDispatcher.invoke(
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(
    at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(
    at com.evermind.server.http.ServletRequestDispatcher.access$100(
    at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(
    at com.evermind.server.http.ServletRequestDispatcher.forward(
    at com.evermind.server.http.EvermindPageContext.forward(
    at _OA._jspService(
    at com.orionserver.http.OrionHttpJspPage.service(
    at oracle.jsp.runtimev2.JspPageTable.service(
    at oracle.jsp.runtimev2.JspServlet.internalService(
    at oracle.jsp.runtimev2.JspServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at com.evermind.server.http.ResourceFilterChain.doFilter(
    at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(
    at com.evermind.server.http.EvermindFilterChain.doFilter(
    at com.evermind.server.http.ServletRequestDispatcher.invoke(

  24. Hi Edwin,

    I tried creating a web service from pl/sql package in Here is my problem posted. Can you please help me?

    Thanks in advance.

  25. I have deployed a plsql web service on weblogic 11g and it works fine. However, sometimes after shutdown/restart of the application server, the webservice fails to start automatically with error "java.sql.SQLException: Error looking up :". The manual start of the webservice also fails. What I do is to go to the configur section of the data source and save it without any changes. Then I can start the web service. Could you advise me about this problem?

    1. Hi,

      can you change the deployment order or enable it should wait for the resource are available. This should be options which you can configure in your weblogic console.


  26. Hi Edwin -

    I'm using Jdevelpoer 11g web service wizard and exposing PL/SQL package as web service.I'm using function inside package which returns XMLTYPE.

    Inside db function I'm using SQLX functions and generate XML. The web service is working fine.

    The issues is web service consumer wants WSDL file with appropriate schema and our WSDL file doesn't have one (since XMLTYPE is function output).

    How can we generate appropriate WSDL file with proper schema? Appreciate your help.

    1. Hi,

      you mean the client needs a XSD or is schema types inside the WDSL is not enough. And is your response an anyType or a String.

      what you can do, is to make a contract first wsdl. design your own wsdl and generate java on this wsdl and then call the already generated EJB.


  27. Hi Edwin,

    I'm trying to get this to work. Thanks in advance for the blog. Just noticed a couple of typos at the beginning (funtion and scherma).

    This is the pl/sql package I will use in this example. The package contains a current time funtion and a procedure which returns all the dept records of the scott scherma. Add this package to the scott schema

    John Zamow