Feeds

Migrating EJB 2.1 Entity and Session Beans to EJB 3.0

The nuts and bolts

The Power of One eBook: Top reasons to choose HP BladeSystem

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.

HP ProLiant Gen8: Integrated lifecycle automation

More from The Register

next story
Whoah! How many Google Play apps want to read your texts?
Google's app permissions far too lax – security firm survey
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Big Blue Apple: IBM to sell iPads, iPhones to enterprises
iOS/2 gear loaded with apps for big biz ... uh oh BlackBerry
prev story

Whitepapers

Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Application security programs and practises
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.