Skip to main content
Jump to: navigation, search

EclipseLink/UserGuide/DBWS/Creating EclipseLink DBWS Services (ELUG)

< EclipseLink‎ | UserGuide‎ | DBWS
Revision as of 13:27, 2 April 2009 by (Talk | contribs) (Binding)

Note: A basic overview of EclipseLink Database Web Services (DBWS) can be found here

Creating Deployable EclipseLink DBWS Services

This section describes how to automatically generate a .war file containing the EclipseLink DBWS service descriptor along with all required deployment artifacts for a JAX-WS 2.0 Web service (WSDL, XML schema, web.xml, EclipseLink ORM and OXM native Project XML files, etc.)

 root of war file
    |   web.xml
    |   +---foo                               -- optional domain classes (typically not required)
    |   |   \---bar                              
    |   |           Address.class
    |   |           Employee.class
    |   |           PhoneNumber.class
    |   |
    |   +---META-INF
    |   |       eclipselink-dbws.xml
    |   |       eclipselink-dbws-or.xml
    |   |       eclipselink-dbws-ox.xml
    |   |       eclipselink-dbws-sessions.xml -- name can be overridden by <sessions-file> entry in eclipselink-dbws.xml
    |   |
    |   \---_dbws
    |           DBWSProvider.class            -- auto-generated JAX-WS 2.0 Provider
EclipseLink DBWS Service .war File Contents
File Description
web.xml The Web application deployment file (required for deployment as a JAX-WS Web service)
eclipselink-dbws.xml The EclipseLink DBWS service descriptor file (described in full in the User Guide)
eclipselink-dbws-or.xml The EclipseLink ORM Project XML file. For more information, see Introduction to Relational Projects (ELUG)
eclipselink-dbws-ox.xml The EclipseLink OXM Project XML file. For more information, see Introduction to XML Projects (ELUG)
eclipselink-dbws-sessions.xml The EclipseLink sessions.xml file for the EclipseLink DBWS service. It contains references to the EclipseLink ORM and OxM Project XML files. For more information, see Introduction to EclipseLink Sessions (ELUG)
eclipselink-dbws-schema.xsd Contains XML type definitions for operation arguments and return types. The DBWSBuilder utility automatically generates this file from the database metadata to derive element-tag names and types
eclipselink-dbws.wsdl Contains entries for all operations in the EclipseLink DBWS service (required for deployment as a JAX-WS Web service)
swaref.xsd (optional) Contains XML type definitions for SOAP attachments

NB - the files swaref.xsd and web.xml have names and content determined by their roles in web deployment and cannot be changed.

The deployable .war file has been verified to work with the Oracle WebLogic Server 10.3 JavaEE container. An alternate deployable .jar file has been
verified to work as a JavaSE 6 'container-less' EndPoint.

This section describes the following:

How to Create EclipseLink DBWS Services Using the DBWSBuilder utility

You can use the EclipseLink DBWS design-time tool DBWSBuilder to create deployment files. DBWSBuilder is a Java application that processes the operations described in an EclipseLink DBWS builder XML file to produce all the required deployment artifacts.

Be sure to set the following environment variables in the <ECLIPSELINK_HOME>\utils\dbws\setenv.cmd (or file) before invoking DBWSBuilder:


There are script files provided for invoking DBWSBuilder. They are located in <ECLIPSELINK_HOME>\utils\dbws. The scripts are dbwsbuilder.cmd for Windows usage and for other operating systems.

DBWSBuilder usage - [] indicates optional argument:
prompt > dbwsbuilder.cmd -builderFile {path_to_builder.xml} -stageDir {path_to_stageDir} -packageAs[:archive_flag] {packager} [additional args]
Available packagers:
  -packageAs:[default=archive] javase [jarFilename]
  -packageAs:[default=archive] wls [warFilename]

Using DBWSBuilder, you can generate an EclipseLink DBWS service from the following sources:

  • an existing relational database table;
  • one or more SQL SELECT statements;
  • a stored procedure.

Using the DBWSBuilder utility to create an EclipseLink DBWS Service from a Database Table

Create an EclipseLink DBWS builder XML File with a <table> query operation:

<?xml version="1.0" encoding="UTF-8"?>
<dbws-builder xmlns:xsd="">
    <property name="projectName">table_test</property>
    ... database properties ...

For more information, see the basic example Creating EclipseLink DBWS Service based on Database Table.

Using the DBWSBuilder utility to create an EclipseLink DBWS Service from a SQL statement

Create an EclipseLink DBWS builder XML File with a <sql> query operation:

<?xml version="1.0" encoding="UTF-8"?> 
<dbws-builder xmlns:xsd="" 
    <property name="projectName">sql_test</property>
    ... database properties ...
  <sql name="employeeInfo" simpleXMLFormatTag="employee-info" xmlTag="aggregate-counts"> 
      <![CDATA[select count(*) as "COUNT", max(SAL) as "MAX-Salary" from EMP]]> 

The SQL SELECT statement for a <sql> operation may have arguments that must be bound to a data type from the eclipselink-dbws-schema.xsd, or to any of the basic XSD data types. The SQL SELECT string uses JDBC-style '?' markers to indicate the position of the argument. The <sql> operation uses nested <binding> elements to match the data type to the arguments. The order in which <binding> elements are defined must match the order of arguments in the SQL statement:

<?xml version="1.0" encoding="UTF-8"?> 
<dbws-builder xmlns:xsd="" 
    <property name="projectName">sql_binding_test</property>
    ... database properties ...
  <sql name="findEmpByName" isCollection="true" isSimpleXMLFormat="true">  
      <![CDATA[select * from EMP where EMPNO = ? and LAST_NAME = ?]]> 
    <binding name="EMPNO" type="xsd:int"/> 
    <binding name="LAST_NAME" type="xsd:string"/> 

The named argument "EMPNO" is bound to an integer type while the named argument "LAST_NAME" is bound to a string type.
For more information, see the basic example Creating EclipseLink DBWS Service based on Results Sets from custom SQL SELECT statements.

Using the DBWSBuilder utility to create an EclipseLink DBWS Service from a Stored Procedure

Create an EclipseLink DBWS builder XML File with a <procedure> query operation:

<?xml version="1.0" encoding="UTF-8"?> 
<dbws-builder xmlns:xsd="" 
    <property name="projectName">procedure_test</property> 
    ... database properties ...

For more information, see the basic example Creating EclipseLink DBWS Service based on Stored Procedure.

How to Customize an EclipseLink DBWS Service

There are a number use-cases that require an EclipseLink DBWS Service to be customized. The use-cases can be sub-divided into

  • simple - changing an <element-tag> to an "attribute"
  • intermediate - customizing the EclipseLink ORM or OXM Projects
  • advanced - hand-generating all required deployment artifacts

Simple EclipseLink DBWS Customization

Intermediate EclipseLink DBWS Customization

with an EclipseLink SessionCustomizer as follows:

  1. Implement a org.eclipse.persistence.config.SessionCustomizer, as the following example shows.

    Implementing a SessionCustomizer
    import org.eclipse.persistence.config.SessionCustomizer; 
    import org.eclipse.persistence.sessions.Session; 
    import org.eclipse.persistence.sessions.DatabaseLogin; 
    public class MySessionCustomizer implements SessionCustomizer { 
      public void customize(Sesssion session) { 
        DatabaseLogin login = (DatabaseLogin)session.getDatasourceLogin(); 

    In the builder XML file, specify if the customization applies to the ORM Project or the OXM Project:

    <?xml version="1.0" encoding="UTF-8"?> 
    <dbws-builder xmlns:xsd="" 
        <property name="projectName">customize_test</property>
        <property name="orSessionCustomizerClassName"></property>


    <?xml version="1.0" encoding="UTF-8"?> 
    <dbws-builder xmlns:xsd="" 
        <property name="projectName">customize_test</property>
        <property name="oxSessionCustomizerClassName"></property>

    Advanced EclipseLink DBWS Customization

    You can customize an EclipseLink DBWS service by creating your own project.xml and sessions.xml files.

    Before you can deploy the EclipseLink database Web service, you must package the WAR in the appropriate Java EE archive for your application, such as an EAR.

    Unstructured Data

    In some circumstances, an EclipseLink database Web services operation may return unstructured data rather than a persistent entity. For example:

    • a resultSet from a custom SQL SELECT statement;
    • information returned by a Stored Procedure;
    • scalar results such as from a Stored Function or a count of updated-rows from an update operation.

    The OC4J Web services provider will return such unstructured data as documents that conform to the Simple XML Format (SXF) schema shown in this example.

    Simple XML Format XSD for Unstructured Data

    <?xml version="1.0" encoding="UTF-8"?> 
    <xsd:schema xmlns:xsd=""> 
    <xsd:complexType name="sxfType"> 
    <xsd:any minOccurs="0"/> 
    <xsd:element name="simple-xml-format" type="sxfType"/> 

    The following example shows a typical unstructured data document. Note the following:

    • Element tag names are direct copies of table column names.
    • The default root-element tag name is simple-xml-format and each row uses the tag name simple-xml. You can customize these element tag names using simpleXMLFormatTagand xmlTag attributes of builder operations (see Common Attributes of Builder Operations).
    • Columnar data uses tag names taken either from the database schema (the actual database column name) or from the stored procedure, stored function, or trigger.

    Example Unstructured Data Document


    EclipseLink Database Web Services Customization

    To customize an EclipseLink database Web service, you can do the following:

    • Implement an EclipseLink SessionCustomizer class.

    A SessionCustomizer is a Java class that implements the interface and provides a default (zero-argument) constructor.

    Use this class's customizemethod, which takes an eclipselink.sessions.Session, to programmatically access advanced EclipseLink session API. Using this API you can get object relational and XML descriptors and from descriptors, you can get object relational and XML mappings.

    In this way, you can access all session, descriptor, and mapping API to customize any part of the EclipseLink runtime that the EclipseLink database Web service generates. For example, to turn off the session cache. This approach is best when you just want to customize a few details.

    You specify the SessionCustomizerusing DBWSBuilder properties (see eclipselink-dbws-builder.xml and #DBWSBuilder).

    By default, the session names are defined based on the eclipselink-dbws.xml file (see eclipselink-dbws.xml File) name attribute as follows:

    • relational session name: name-dbws-or-session
    • object-xml session name: name-dbws-ox-session
    • Manually generate project.xml files and sessions.xml file.

    Using your preferred tool you can map your objects to your relational database in an EclipseLink relational project, map your objects to your XML schema in an EclipseLink XMl project, and create an EclipseLink sessions.xmlfile that references both projects.

    In this way, you can control all aspects of the relational and XML mapping. This approach is best when you want to customize most or all details.

    DBWSBuilder API

    The EclipseLink database Web service design-time tool, DBWSBuilder, is a Java application that produces EclipseLink database Web service files and assembles them into a Web Archive (WAR) file.

    You set the DBWSBuilder’s properties (see eclipselink-dbws-builder.xml File Elements (DBWSBuilder Properties)) to define features of your EclipseLink database Web service.

    You can also set the design-time tool’s properties, add table and procedure definitions, and SQL operations programmatically through the API. Use the class’s methods such as setDriver, setProjectName, setURL, and so on, to set properties; the addDbTableand addDbStoredProceduremethods-to add table and procedure definitions; and the addSQLOperation method-to add SQL operations.

    Note: Before adding a table or procedure definition, ensure that the definitions are supported by calling the checkTablesand checkStoredProcedures methods.

    Once you set all the data and definitions, invoke the builder using its build method.

    Copyright Statement

Back to the top