Creating Message Driven Beans – Total Strangers can work!


“Remember when I first met you? You totally blew off my mind. All of sudden, we click”.

Since the Birth of Enterprise Development, many companies have developed proprietary systems to handle their specific needs, this made merging B2B’s almost impossible as it there isn’t any “Middleman” to clearly handle their differences! The Birth of MOM (message oriented middleware) made possible for distributed applications to “communicate” in the form of send/receive messaging, and as years gone by, many technologies emerged to support such architecture (Spring, EJB).

Here’s a basic tutorial on Message Driven Beans:

Basic stuff right?

More message driven applications will be posted. 🙂

Creating Stateful Session Bean – Lets Finish this together!


How about giving me reference instance copy? How about passing it around by reference and value? Stateless Session Beans are design to store bean composition all throughout its session level life. Composition = can be the client’s state (design the bean directly as an entity manager bean) or object’s lifecycle composition (storing entity definition until its all said and done – transact commit).

Here’s a brief tutorial on Stateful Session Bean:

Again, its a basic one. No Database Transactions involve.

thou shall not worry though, real application scenario tutorial using EJB/JPA will soon be posted. 🙂

Creating Stateless Session Bean – Just Do It! :)


Thats what an application client tells a stateless session bean, “just get the job done, I don’t care if you succeed or not, just give me something in return and I’ll handle the response that the user will get”. Well stateless session beans doesn’t handle client state, thus every time a client requests a bean from a container, it just pull some bean instance and calls the requested processing method.

Tto set things up though, heres a simple Simple Stateless Session Bean Tutorial.

Its the most basic of all basics.. 🙂

Though I would still assume developing this one in NetBeans brings more “basics”.

EJB a Quick Tutorial (Session Beans)


While learning Enterprise Java Beans, I quickly ask myself, what are the advantages of trying to learn it? What can it do to me?.. Well again as part of my growing itch in learning software technologies, I believe learning and understanding EJB will open me up to more JEE complex topics like Web Services, SOA etc.

My first hands-on exercise back then is that basic stuff: Implementing Stateless Session Beans and the Difference between @Local and @Remote. Here’s a quick Stateless Session Bean code I created:

package com.moneymarket.ejb;

import javax.ejb.Stateless;
import moneymarketejbstubs.AccountBeanService;

/**
 *
 * @author Alvin Jay Reyes
 */

@Stateless
public class AccountBean implements AccountBeanService {

    public String sampleBeanRemote() {
        return "SampleBeanRemote";
    }
}

Stateless = means does not save conversational state (well thats why they call it Stateless).

This is just a simple Stateless Session Bean with a method called sampleBeanRemote(). We have to tell the compiler that our Session Bean can be distributed to remote systems. This is done by implementing the AccountBeanService interface:

import javax.ejb.Remote;

/**
 *
 * @author Alvin Jay Reyes
 */
@Remote
public interface AccountBeanService {
    public String sampleBeanRemote();
}

Now a bit of explanation of why is there a @Remote annotation. What’s totally awesome with using Enterprise Java Bean is the it can be completely independent and can be distributed to any Java Application (this includes Stand alone J2SE apps and RIAs). This remote object will act as remote client’s “reference” to the deployed Enterprise Java Bean.

Hence, this reference should exist in a different JAR file and developers must use this JAR file to get a reference of the deployed EJB. Take a look at the screenshot of my sample project below:

The Stub Project above is an Enterprise Application Client. This is the standard deployment if we want to generate custom stubs for out EJB.

Generate the Web Application Project to use the Stub to get a reference of the Session Bean and checkout the following code below for the actual call:

import javax.ejb.EJB;
import moneymarketejbstubs.AccountBeanService;

/**
 *
 * @author Alvin Jay Reyes
 */
public class NewService {

    @EJB
    private AccountBeanService ab;
    /** Creates a new instance of NewService */
    public NewService() {
    }

    public String retMe() {
        return ab.sampleBeanRemote();
    }
}
//Call the retMe() object outside this class (a Session Facade or ManagedBean object).

Yep, all you need is the @EJB annotation and the actual remote reference. Thats what I like with EJB 3.0, it makes life easier. Use the @EJB annotation and you’ll quickly get a reference of the Bean and its services.

This is the most basic stuff for implementing Enterprise Java Beans, note that EJB is wide topic as it has a lot of powerful features (interceptors, timers etc.)