advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
Average Rating: 4.9/5 | Rate this item | 7 users have rated this item.
 Print Print
 
Creating Container-managed Entity Beans with JBoss
Entity JavaBeans that use container-managed persistence (CMP) are convenient, because they require so little custom code to achieve automatic persistence. But that convenience carries a price: beans using CMP are also ferociously complex to configure, and often difficult to debug. In this article, you will see how to create, configure, and deploy entity beans that use CMP and JBoss. 

advertisement
n Entity Bean is an Enterprise JavaBean (EJB) that represents a persistent object in a relational database. JBoss provides two methods of entity bean persistence, Bean Managed Persistence (BMP) and Container-Managed Persistence (CMP). With BMP, the entity bean developer must implement all the persistence logic. With CMP, the application server manages entity bean persistence; the developer provides interfaces and configuration.


Applications that use entity beans—particularly entity beans that use CMP— quickly become complex. Therefore, to describe the configuration process in detail without getting bogged down by code complexity, I designed the sample application for this article, JBlog, to be functional and illustrative, yet simple. I also wanted a timely example, which led to the idea of blogging. JBlog is a small blogger application that uses CMP entity beans to persist blog content.

What You Need
To build and run the sample JBlog application, you need JBoss 3.2.1, Java 2 SDK 1.4, Java 2 EE SDK 1.3, Ant 1.5, and JUnit 3.8.1.

JBlog's interface consists of two Web pages, one for viewing a blog and one for posting new entries. The interface uses two entity beans: Story for blog entries and Author for content authors. In the rest of this article, you'll see how to construct, configure, and persist those entity beans.

An entity bean using CMP has several interfaces, explained in the following sections. You don't have to implement all the interfaces for every CMP entity bean.

The Home Interface (optional)
External clients use an entity bean's home interface to create, remove, and find instances of the entity bean. You don't need to create a home interface if external clients will not use the bean directly. The home interface defines the following methods:

  • Create. Creates an entity bean instance.
  • Remove. (required) Removes an entity bean instance.
  • Finder methods. Find one or more entity bean instances. Finder method names must start with "find". For a CMP entity bean, the finder method findByPrimaryKey must be defined.
  • Home methods. These methods act like static methods for an entity bean. Home methods can be called from the home interface (remote or local) to execute entity bean methods without creating an instance of the entity bean.
Both the entity beans in JBlog have home interfaces. To see the full code, look at the StoryHome.java and AuthorHome.java files in the JBlog source directory. The main page (index.jsp) uses the AuthorHome interface to find the author "bigt."

   // Create AuthorHome.
   AuthorHome authorHome = (AuthorHome) PortableRemoteObject.narrow(
      ctx.lookup("ejb/JBlog/Author"), AuthorHome.class);
   
   // Find author.
   Author author = authorHome.findByPrimaryKey("bigt");

Page 1 of 6


advertisement
  Next Page: The Remote Interface (optional)
Page 1: IntroductionPage 4: Specifying Bean Relationships in the EJB Jar Descriptor File
Page 2: The Remote Interface (optional)Page 5: The JBoss CMP Descriptor File
Page 3: The Entity Bean ClassPage 6: Specifying Bean Relationships in the JBoss CMP Descriptor File
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES