Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 

Creating an Entity Bean


by jGuru

Exercise | API Docs | Short Course| Exercises

Help is available for each task.



    Task 1

    Design a MusicCD remote interface and a MusicCDHome home interface. The MusicCD bean must encapsulate the persistent fields upc, title, artist, type, and price, so the MusicCD remote interface should define accessors and mutators for these persistent fields. The MusicCDHome interface should define a findByPrimaryKey() method which accepts a String argument for the upc, and a create() method that accepts a upc.


    Remember that all of the methods in the remote interface must throw RemoteException and that the create() methods in the home interface must return an object of type MusicCD.

    Task 2

    Code the MusicCDBean entity bean implementation class. You need to provide implementations for all the methods defined in the remote interface, plus you need to implement all the methods defined in the EntityBean interface. You also need to provide an implementation of ejbCreate() with the same number and datatypes of arguments as you defined in the create() method of your home interface.


    MusicCDHome should prescribe a single bean-creation method with the signature:

    public MusicCD create(String upc)
                   throws CreateException, RemoteException;
    
    but the implementation of this in the bean class must return null in the case of container-managed persistence.

    Because MusicCDBean is an implementation of an entity bean, it has a primary key and it must have a creation methods with arguments to initialize the key: create() and ejbCreate().

    Task 3

    Compile all the classes that compose your bean.


    Don't forget that the compiler needs to be able to find the javax.ejb classes, which are in J2EE_HOME/j2ee.jar. You may use the following command to compile:

    javac -classpath %CLASSPATH%;%J2EE_HOME%\lib\j2ee.jar;. musicstore\*.java

    Task 4

    Package your entity bean into a jar file, using the provided XML deployment descriptor.


    Execute the command jar cvf MusicCD.jar musicstore\*.class META-INF\ejb-jar.xml to create the jar file.

Copyright 1996-2000 jGuru.com. All Rights Reserved.


Print Button
[ This page was updated: 14-Apr-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.