Friday, July 11, 2008

Using EJB in Flex with blazeds

This blog explains how you can use ejb in Adobe Flex with blazeds. First thing I did is creating a application with the jsf, ejb template.

In the model project we can create a new entity bean. I use the CMP entity bean from tables.

For the EJB version I use Enterprise JavaBeans 2.1 option. The Oracle table I will use in this entity bean is the employee table of the HR schema.

Now we can create a Session Bean
If we look at the properties of the session bean we see the retrieveAllEmployees method. We will use this to display all the employees in flex.

We are ready to add the blazeds libraries to the viewcontroller project. Because we want to use EJB, we have to download an extra library. Here is the link of the ejb library which is made by Ryan J. Norris. Add also this library to the viewcontroller project.
Because we use ejb we have to add the embedded oc4j client and j2ee library to viewcontroller project.

Now we can configure blazeds. We have to create two files (remoting-config.xml and services-config.xml ) in WEB-INF/flex/ folder
Here is the remoting-config.xml file. In this file we define a destination with the name of the session bean in the model project.

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" class="">
<adapter-definition id="java-object"
<channel ref="my-amf"/>
<destination id="EmployeeEJB">

Here is the services-config.xml. In this file we define the ejb factory in my case I have to use for ejb3 we have to use as factory class.

<?xml version="1.0" encoding="UTF-8"?>
<service-include file-path="remoting-config.xml"/>
<channel ref="my-amf"/>
<factory id="ejb" class="" />
<channel-definition id="my-amf"
<endpoint url="http://{}:{server.port}/{context.root}/messagebroker/amf"

<target class="flex.messaging.log.ConsoleTarget" level="Error">
<prefix>[Flex] </prefix>

Add the blazeds servlet to the web.xml




The last step in jdeveloper is to add to the run options of the viewcontroller project.

Let's open Flex builder 3 and create a new project.

We have to select j2ee server technology.

The second step is to add the webapp url's.
The mxml is very simple. First we add a remoteobject, then we are calling theretrieveAllEmployees method when the application is loaded and at last we display the result in a datagrid.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=""
width="1155" height="206.21213">

<mx:RemoteObject id="srv" showBusyCursor="true"
<mx:DataGrid width="1104.6212"


Here the result. That's all.


  1. Hi! This guide seems to be very helpful and simple, but i can't understand which software/plugin you are using on the first screenshot. Is that a plugin for Eclipse? Thanks!

  2. Hi, The picture is a wizard in JDeveloper.

    maybe Oracle will make more plugin for eclipse now they own BEA


  3. JDeveloper works only with Oracle DB? Could i use it with a SQL Server DB?


  4. Hi jdev can work perfectly with any database. just use the right jdbc driver.

    only adf bc can not work 100% , but you use ejb.


  5. I have doubt in blazeDS.

    i am trying to connect the EJB and Flex with BlazeDS.

    i am going to write the EJB using Rational application developer and
    Flex using Flex Builder.

    the database i am going to use is DB2,

    is it possible to connect.

    please share your experience


  6. is it possible to plug-in the BlazeDS in Rational Application Development.


  7. Hi areef,

    Blazeds should work in every j2ee container. The only thing you should do is to add a servlet to the web.xml and add some folder with config files and lib to the web-inf folder ,

    And the ejb should work also.


  8. hi biemond.. why don't you give us the full source code of projects. when we use other IDEs except for JDeveloper, it becomes difficult to imagine the whole part especially for newbees.

  9. If you need support for stateful session beans have a look at

  10. Hi Dan,

    Good work. Maybe you can also take a look at Remote Development Services in FB4. RDS does not work in FB4 with EJB. Maybe you can make it work.