Package examples.ejb20.relationships.bands
This example is a package that demonstrates the use of local interfaces; one-to-one, one-to-many, many-to-many relationships; client.jar; automatic primary key generation; and automatic table creation.See:
Interface Summary
Artist ArtistHome Band BandHome FanClub FanClubHome MusicLibrary MusicLibraryHome Recording RecordingHome
Class Summary
ArtistBean BandBean BandInfo BandPK Client This example demonstrates EJB relationships. FanClubBean FanClubPK MusicLibraryBean RecordingBean RecordingInfo RecordingPK Package examples.ejb20.relationships.bands Description
This example is a package that demonstrates the use of local interfaces; one-to-one, one-to-many, many-to-many relationships; client.jar; automatic primary key generation; and automatic table creation. It uses EJBs written to the EJB 2.0 specification.
The example includes entity EJBeans called ArtistBean, BandBean, FanClubBean, and RecordingBean and a stateless session bean called MusicLibraryBean.
The example demonstrates:
- Using an entity EJBean written to the EJB 2.0 specification
- Using a stateless session EJBean written to the EJB 2.0 specification
- Showing a one-to-one relationship between Fan Club and Band
- Showing a one-to-many relationship between Band and Recording
- Client application
Client application
The Client application performs these steps:
- Review the Music Library
- Provides a list of the bands in the Music Library
- Provides a list of recordings for each band in the Music Library
- Displays Fan Club information for each artist in the Music Library
To get the most out of this example, first read through the source code files.
Start with the XML deployment files ejb-jar.xml, weblogic-ejb-jar.xml and weblogic-cmp-rdbms-jar.xml to find the general structure of the EJBean, which classes are used for the different objects and interfaces, then look at Client code to see how the application works.
- Client applications
- Client.java
- Interfaces
- Artist.java
- ArtistHome.java
- Band.java
- BandHome.java
- BandInfo.java
- FanClubHome.java
- MusicLibrary.java
- MusicLibraryHome.java
- Recording.java
- RecordingHome.java
- RecordingInfo.java
- Deployment
- ejb-jar.xml
- weblogic-ejb-jar.xml
- weblogic-cmp-rdbms-jar.xml
- Server (EJBean)
- ArtistBean.java
- BandBean.java
- FanClubBean.java
- MusicLibraryBean.java
- RecordingBean.java
Pre-Built Examples
This EJB 2.0 example is not shipped pre-built. Before you can run this example, first create a table in Oracle, build the example following the instructions in Build the example, and then run the example using the instructions below.
The following four sections cover what to do:
Set up the database
This example is preconfigured to work with the PointBase database, included with the WebLogic Server distribution. As you'll use a database for the persistent storage of the entity EJBean, you'll need to set it up. The persistent storage is completely invisible to the client; the actual storage is handled by the EJBean directly and not the container.With database persistence, each instance of an EJBean is written to a row in a table. If you want or need to run this example with Oracle, see Database SetUp for instructions.
The following tables, created using the table.ddl file supplied with this example's package must be created and exist in the database before you run example:
- fanclubs
- recordings
- artists
- bands
- band_artist
- artist_sequence
The persistent storage is completely invisible to the client; the actual storage is handled automatically by the container and not by the EJB.
Build the example
Set up your development shell as described in Setting up your environment.We provide a build script for you to build the example:
The build script is build.xml.
Run the build script using the following Java ant command:
prompt> antThe script builds the example and places the files in the correct locations in your WebLogic Server distribution:
- Client.jar file: in SAMPLES_HOME\server\examples\build\clientclasses
- EJB (in EAR file): in SAMPLES_HOME\domains\examples\applications\ejb20_relationship_bands.ear
Running the build script places the EJB in the %applications% directory, where it automatically deploys once the server is started. If you are already running the server and then build the EJB, it is automatically placed in this directory and instantly deployed.
Additional information on using the build scripts is found in More About Building Examples.
Start the Examples server
- Start the Examples server.
If you need more information about how to use connection pools, read Using WebLogic JDBC: Using connection pools.
Run the example
- Run the client in a separate command line window. Set up your client as described in Setting up your environment, and then run the client by entering:
prompt> ant run
- You should receive output similar to this:
Welcome to the Hipster Music Library... Added these bands... Band Name: Genesis Band Founder: Peter Gabriel startDate: 1969-12-31 Band Name: Beastie Boys Band Founder: Mike Diamond startDate: 1981-12-31 Band Name: Britney Spears Band Founder: Britney Spears startDate: 1997-12-31 Band Name: Seth's Saxophone All-Stars Band Founder: Saxophone Seth startDate: 19 98-11-12 Added these Recordings... Recording: Title: Duke Band: Genesis Recording Date: 1982-03-05 Recording: Title: Invisible Touch Band: Genesis Recording Date: 1985-03-05 Recording: Title: Sounds of Science Band: Beastie Boys Recording Date: 1997-03-0 5 Recording: Title: Licensed To Ill Band: Beastie Boys Recording Date: 1990-03-05 Recording: Title: Paul's Boutique Band: Beastie Boys Recording Date: 1989-03-05 Recording: Title: Britney's First Album Band: Britney Spears Recording Date: 19 99-03-05 Recording: Title: Saxophone Seth Plays the Blues Band: Seth's Saxophone All-Star s Recording Date: 2001-03-23 Printing out Fan-Club Write-Up for each Band Write-up for band: Genesis is: Genesis Fan Club Write-up for band: Beastie Boys is: Beastie Boys Fan Club Write-up for band: Britney Spears is: Britney Spears Fan Club Write-up for band: Seth's Saxophone All-Stars is: Seth's Saxophone All-Stars Fan Club Good bye...There's more... Read more about:
- EJB in the BEA WebLogic Server Enterprise Java Beans