Hi,
I've resolved my problems with the Orion primer
example. I had to create a
$(ORION_HOME)/database directory and everything
seems to work fine!
For the people who wants to try CMP, I've attached
the Orion CMP primer example.
Don't forget to create the $(ORION_HOME)/database
directory!!
Thanks.
>hi fresnaULL﹕
>When I created a database directory ($ORION_DIR/database) and >test the news demo app again, I get new erroe message: >com.evermind.server.rmi.OrionRemoteException: Database error: Table not found: >COM_EVERMIND_EJB_NEWSITEM in statement [select >com_evermind_ejb_NewsItem.id, com_evermind_ejb_NewsItem.submitter, >com_evermind_ejb_NewsItem.text, com_evermind_ejb_NewsItem.locale, >com_evermind_ejb_NewsItem.date, com_evermind_ejb_NewsItem.subject, >com_evermind_ejb_NewsItem.parent from com_evermind_ejb_NewsItem where >com_evermind_ejb_NewsItem.parent = NULL] >at NewsItemHome_EntityHomeWrapper4.findByParent(NewsItemHome_EntityHomeWrapper4.java, Compiled Code) >at com.evermind.ejb.NewsSessionEJB.getChildren(NewsSessionEJB.java, >Compiled Code) >at NewsSession_StatefulSessionBeanWrapper1.getChildren>(NewsSession_StatefulSessionBeanWrapper1.java:66) >at /news.jsp._jspService(/news.jsp.java:83) (JSP page line 26) >at com.orionserver.http.OrionHttpJspPage.service(JAX) >at com.evermind.server.http.HttpApplication.xa(JAX) >at com.evermind.server.http.JSPServlet.service(JAX) >at com.evermind.server.http.d3.so(JAX, Compiled Code) >at com.evermind.server.http.d3.sm(JAX) >at com.evermind.server.http.ef.su(JAX, Compiled Code) >at com.evermind.server.http.ef.dn(JAX, Compiled Code) >at com.evermind.util.f.run(JAX, Compiled Code) >Nested exception is: >... >What should I do in next step ? Where can I get more docs ? >Thank you very much. >bubble (2000/11/23 PM 11:46:07) >[EMAIL PROTECTED] ======================================================= > > Hi. > No, I haven't created any database directory. This is the first time I hear > about > that!! . Could you tell me what I have to do?, I mean, > What is this directory for? What about the defaultdb file in it? Where did > you > read about that? > > Thank you very much. > > > ----- Original Message ----- > From: KirkYarina <[EMAIL PROTECTED]> > To: Orion-Interest <[EMAIL PROTECTED]> > Sent: Wednesday, November 22, 2000 9:35 PM > Subject: Re: Problems with the Orion CMP primer example. > > > > Have you created a database directory ($ORION_DIR/database)? Do you have > > the appropriate permissions on defaultdb.* in it? > > > > At 12:10 PM 11/22/00 +0000, you wrote: > > > > >Hi, > > >I'm trying to deploy the Orion CMP primer example. I've follow the > > >instructions but I've got the following error: > > > > > >Auto-deploying addressbook (New server version detected)... > > >Auto-deploying addressbook-ejb.jar (No previous deployment found)... SQL > > > error: File input/output error: ./database/defaultdb.properties > > >Warning: Error creating table: File input/output error: > > >./database/defaultdb.pro > > > perties > > >done > > >Orion/1.3.8 initialized > > > > > >I'm sure I've installed Orion properly because I've deployed successfully > > >the > > >Orion Primer example. > > > > > >Thanks in advance > > > > > > Kirk Yarina > > [EMAIL PROTECTED] > > > > > PC home 免費電子信箱,申請請至: http://www.pchome.com.tw PC home Online 網路家庭 會員第一,台灣最大的入口網站 |
This article will show you how to write and run a simple Container-Managed Persistent Entity Bean using the Orion application server (http://www.orionserver.com/).
The Orion Primer showed you how to write, compile and deploy a servlet and a session bean. This article will show you how to write a Container Managed Entity Bean as well as an HTML page and a JSP that you can use to access the entity bean. We will first draw a sketch of what we are going to build. Then we'll set up
a directory structure for this, and write the necessary HTML, JSP and Java
files. After that we will build the JAR, WAR and EAR files and deploy them into
Orion. Before you start, make sure you have downloaded and installed the following software:
This article has the following sections:
For this example, we will create a small address book application. Users will be able to list, add, edit and delete address entries. No security will be involved at this time, so all users will be able to perform these operations. Here's a sketch of what the structure of our J2EE application will be:
![]() The web application will contain the files needed to implement the front end for our address book application. We will create a HTML page to represent the front page, and one JSP per action.
First thing we do, is set up a directory structure that will contain all of
the files we write and those we generate. You should create the
During this exercise we will put all source files in the following directory structure: addressbook addressbook/etc addressbook/src addressbook/src/java addressbook/src/java/addressbook addressbook/src/java/addressbook/ejb addressbook/src/jsp addressbook/src/web All The directory The generated files will end up in the When archives are created, they will be placed under
Now for the back end we will write an interface for your bean, just as we did
in the Orion Primer. Again the
new interface will be derived from
public interface AddressEntry extends EJBObject { public String getName() throws RemoteException public String getAddress() throws RemoteException public String getCity() throws RemoteException public void setAddress(String newAddress) throws RemoteException public void setCity(String newCity) throws RemoteException }
Again, we have the interface that the clients can use to modify an existing bean. So far there are little differences visible between the session bean developed in the Orion Primer trail, and the entity bean we are developing now. Now let's look at the entity bean. This is a class that must implement the
interface public class AddressEntryBean extends Object implements EntityBean This class will need to contain the following things:
The
The EJB specification mandates that we add an
Note that we have some additional functionality in our bean. We have a class
field
For this, the bean uses a class called
A home interface is used to create and destroy instances of Enterprise
JavaBeans. So we need a home interface for our The home interface will be derived from public interface AddressBook extends EJBHome { public AddressEntry create(String name, String address, String city); public AddressEntry findByPrimaryKey(String name); public Collection findAll(); } We need to use this interface from our JSP pages to get a reference to an
instance of
This is all we need to do for our home interface. Orion will create an implementation for this interface that will implement the behaviour we need. Life doesn't have to be complicated !
We need an XML deployment descriptor that will describe the EJB part of our application. In the deployment descriptor we describe every Enterprise JavaBean we would like to deploy. In our case, there is only one. This time it's an entity bean: <entity> <display-name>Address book entry</display-name> <ejb-name>addressbook.ejb.AddressEntry</ejb-name> <home>addressbook.ejb.AddressBook</home> <remote>addressbook.ejb.AddressEntry</remote> <ejb-class>addressbook.ejb.AddressEntryBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.util.String</prim-key-class> <reentrant>False</reentrant> <cmp-field><field-name>name</field-name></cmp-field> <cmp-field><field-name>address</field-name></cmp-field> <cmp-field><field-name>city</field-name></cmp-field> <primkey-field>name</primkey-field> </entity> This deployment descriptor specifies some characteristics for the entity bean, including the fields the EJB container (Orion in this case) should persist and what the primary key is.
It is now time to create the files that implement the front end of our application. This is the web module. We will create a single HTML page as the front page, and 4 JSP files, one per action:
We can visualize this as follows:
![]() The idea of this article is not to teach you how to write JSP's, it helps you get your feet wet. See the links at the bottom of this article for links to more information that will help you improve your skills.
This is all there is to the front end. Take a good look at the code and make sure you get the general idea. The code contains quite some documentation to help you understand what goes on.
The descriptor for our J2EE web module is very simple. With optional things removed it looks like this:
<web-app> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <ejb-ref> <ejb-ref-name>ejb/AddressBook</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>addressbook.ejb.AddressBook</home> <remote>addressbook.ejb.AddressEntry</remote> </ejb-ref> </web-app> The The
Now we need to combine the EJB module and the web module into a J2EE application. For this we need to write a J2EE application deployment descriptor. This is an XML file that defines the modules of a Java 2 Enterprise Edition application, and how they should be deployed. In our case we can keep the file very simple: <application> <module> <ejb>addressbook-ejb.jar</ejb> </module> <module> <web> <web-uri>addressbook-web.war</web-uri> <context-root>addressbook-web</context-root> </web> </module> <application> The root tag is
An
META-INF/ META-INF/application.xml addressbook-ejb.jar addressbook-web.war The
META-INF/ META-INF/ejb-jar.xml addressbook/ addressbook/ejb/AddressEntry.class addressbook/ejb/AddressBook.class addressbook/ejb/AddressEntryBean.class The file
WEB-INF/ WEB-INF/web.xml index.html list.jsp add.jsp edit.jsp delete.jsp For this purpose, I have written an Ant build file that will compile all the
In this file you may want to change one or two settings:
We are now ready to generate the class files, the web module archive
(
This will (should) create the following files. Click on one to download the files generated on my system:
lib/ejb/addressbook/ejb/AddressEntry.class lib/ejb/addressbook/ejb/AddressEntryBean.class lib/ejb/addressbook/ejb/AddressBook.class build/addressbook-ejb.jar build/addressbook-web.war build/addressbook.ear
To actually install our application, you need to add a line like the
following to your
<application name="addressbook" path="path to ear file" /> In my case:
<application name="addressbook" path="/home/ernst/projects/addressbook/build/addressbook.ear" /> Please make sure that the process that will run Orion has write
access to the directory that contains the
Now we need to bind the web application to the default site. This is done by
adding the following line to the file
<web-app application="addressbook" name="addressbook-web" root="/addressbook" />
Everything should work, so let's start Orion.
You should see some log messages from Orion now. The exact messages depend on your version of Orion and configuration. On my system I got this:
Now open your favourite webbrowser, and point it to:
http://hostname:port/addressbook/ In my case I am running the Orion webserver on a different computer, that computer has IP address 10.0.0.1, and it runs Orion on port 9000:
http://10.0.0.1:9000/addressbook/ As soon as you access the web module, you should see a message appear in the screen you started Orion in, something like:
You should see the
![]() You can test the JSP pages by clicking on the link. You should see a screen indicating that there are no entries found, similar to the following:
![]() Add entries using the Add entry link. After submitting a new address you will return to the Add address screen until you click the Back to the list link. After adding a few addresses the list page will look similar to this:
![]() When you change anything in one of the deployment descriptors, JSP pages or
Java source files, rerun
See the following pages for more information on Orion:
See the following sites for more information on Enterprise JavaBeans (EJB) and Java 2 Enterprise Edition (J2EE):
|