Now that both entity beans are coded and the RockSurvey2Bean
's persistence method is complete, it's time to add the final information to the deployment descriptor and actually deploy Take 2 of the Rock Survey:
-
If you haven't already, compile the Java source files in the Survey2 directory, or copy the .class files from the
prod
folder.
-
Start J2EE and
deploytool
.
-
Ensure that the Cloudscape database is started.
Create new Enterprise JavaBean component — SurveyBean
-
Ensure that Application Survey2App is selected.
-
From the menu, select File, New, Enterprise Bean — Intro display appears; click Next.
-
Select Add to Existing JAR File.
-
Select Survey2JAR in the drop-down menu.
-
Click Edit.
-
Select the .class files that comprise the bean. These are:
SurveyBean.class
SurveyLocal.class
SurveyLocalHome.class
-
Click Add; click OK; click Next.
-
Under Bean Type, click Entity.
-
In the Enterprise Bean Class combo box, select the bean implementation: SurveyBean.
-
In Enterprise Bean Name, accept SurveyBean.
-
Select the corresponding interfaces in the combo boxes:
For Local Home Interface, select: SurveyLocalHome.
For Local Interface, select: SurveyLocal.
-
Click Next.
-
Ensure that Container Managed Persistence 2.0 is selected under Persistence Management.
-
In Abstract Scheme Name, key Survey.
-
Select all of the check boxes in the "Fields to be persisted" scrolled list.
-
Key java.lang.String in the Primary Key Class textfield.
-
Select "type" in the Primary Key Field Name drop-down menu. Click Next; click Finish.
-
SurveyBean now appears under Survey2JAR under Survey2App.
-
Click the Entity tab, then click Deployment Settings.
-
Unselect the check boxes under Database Table.
-
Click Database Settings.
-
Under Database JNDI Name, enter "jdbc/gsejbDB".
-
Click OK.
-
Click Generate Default SQL.
If you want to see the generated SQL, click Container Methods, then click on each method. Do not change anything in the SQL Query box; deploytool
does not track changes properly, and you'll get to do everything over again. You can also see the table name and columns generated by the container. Note that there is no vendor independent means of describing the name.
-
Click OK.
-
Click the Security tab.
-
Under Method Permissions, click Local Home. Change Availability for the
remove()
method to No Users. Click Local. Change Availability for the remove()
method to No Users. No deletes are allowed.
-
Select Survey2JAR, then click the JNDI Names tab.
-
Under EJBs, key ejb/SurveyBean next to SurveyBean.
Modify Enterprise JavaBean component — RockSurvey2Bean
- Select RockSurvey2Bean.
-
Select the EJB Refs tab; click Add.
-
When the bean invokes the lookup method, it refers to the home of an enterprise bean like this:
Object objRef = ic.lookup("java:comp/env/ejb/SurveyBean");
So, in the Coded Name column, enter ejb/SurveyBean.
-
Select Entity for Type and Local for Interfaces.
-
For Home Interface, enter SurveyLocalHome.
-
In the Local/Remote Interface column, enter SurveyLocal.
-
At the bottom, select
ejb-jar-ic.jar#SurveyBean
from the Enterprise Bean Name drop-down menu.
Deployment
-
Select Survey2App.
-
Select Tools, Deploy from the menu.
-
Under Object To Deploy, ensure that Survey2App is selected.
-
Under Target Server, we are using localhost. Be sure that is
selected.
-
Select the Return Client JAR check box.
-
Select Save object before deploying.
-
Click Next.
-
Verify that the JNDI names are correct, then click Next.
-
Key "/Survey2App" in the context root.
-
Click Next, then Finish.
-
The Deployment Progress dialog will display. Wait until the progress bars are complete and the Cancel button changes to OK, then click OK.
The Survey2App application is deployed.
If you look in the Survey2 folder, you will see that it now contains Survey2App.ear and Survey2AppClient.jar. To run the Survey2App, start both J2EE and Cloudscape, then start up your browser and enter http://localhost:8000/Alice
. When the Alice's World home page appears, click on the "Alice's Surveys - Take 2" link.