Feeds

Migrating EJB 2.1 Entity and Session Beans to EJB 3.0

The nuts and bolts

Providing a secure and efficient Helpdesk

Listing 5. EJB 3.0 Session Bean Client Class

public class CatalogClient {
    @Inject CatalogBean;
    CatalogBean catalogBean;

    String publisher="OReilly";
    String journal=catalogBean.getJournal(publisher);
    System.out.println("Journal for Publisher: "+publisher +" "+journal);
}

Migrating an Entity Bean

In this section, we shall migrate an EJB 2.1 entity bean to the EJB 3.0 specification. An EJB 2.1 entity bean implements the EntityBean interface. An entity bean consists of getter/setter CMP (container managed persistence) field methods, getter/setter CMR (container managed relationships) field methods, callback methods and ejbCreate/ejbPostCreate methods. The example entity bean, CatalogBean.java, that will be migrated to EJB 3.0, includes a local component interface, CatalogLocal.java, a local home interface, catalogLocalHome.java and the ejb-jar.xml deployment descriptor. The EJB 2.1 entity bean is listed in Listing 6.

Listing 6. CatalogBean.java. EJB 2.1 Entity Bean

import javax.ejb.EntityBean;
import javax.ejb.EntityContext;

public class CatalogBean implements EntityBean {
    private EntityContext ctx;

    public abstract void setCatalogId();
    public abstract String getCatalogId();

    public abstract void setJournal();
    public abstract String getJournal();

    public abstract void setPublisher();
    public abstract String getPublisher();

    public abstract void setEditions(java.util.Collection editions);

    public abstract java.util.Collection getEditions();

    public String ejbCreate(String catalogId) {
        setCatalogId(catalogId);
        return null;
    }

    public void ejbRemove() {}
    public void ejbActivate() {}
    public void ejbPassivate() {}
    public void ejbLoad() {}
    public void ejbStore() {}

    public void setEntityContext(EntityContext ctx) {
        this.ctx=ctx;
    }

    public void unsetEntityContext() {
        ctx = null;
    }
}

The ejb-jar.xml deployment descriptor specifies the EJB classes/interfaces, CMP fields, EJB QL queries, and CMR relationships. The CatalogBean entity bean includes a finder method, findByJournal; and a CMR relationship with another entity bean, Edition. The ejb-jar.xml for the CatalogBean EJB is listed in Listing 7.

Choosing a cloud hosting partner with confidence

More from The Register

next story
Microsoft WINDOWS 10: Seven ATE Nine. Or Eight did really
Windows NEIN skipped, tech preview due out on Wednesday
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
'Google is NOT the gatekeeper to the web, as some claim'
Plus: 'Pretty sure iOS 8.0.2 will just turn the iPhone into a fax machine'
prev story

Whitepapers

A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Beginner's guide to SSL certificates
De-mystify the technology involved and give you the information you need to make the best decision when considering your online security options.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.