⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch05s09.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Packaging and deploying the Beans</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html" title="Chapter 5. Using container-managed persistence"><link rel="previous" href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html" title="Creating the Beans"><link rel="next" href="ch05s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s10.html" title="Creating a test client "></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch05s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s10.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e1888"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e1888"></a>Packaging and deploying the Beans</h2></div></div><p>Deploying an entity bean requires providing some extra information, in 
addition to that required 
for a session bean. This information is provided in the deployment descriptor 
ejb-jar.xml</p><pre class="programlisting">
&lt;?xml version="1.0"?&gt;

&lt;ejb-jar&gt;
  &lt;display-name&gt;MusicCDs&lt;/display-name&gt;
  &lt;enterprise-beans&gt;

    &lt;entity&gt;
      &lt;description&gt;Models a music CD&lt;/description&gt;
      &lt;ejb-name&gt;CDBean&lt;/ejb-name&gt;
      &lt;home&gt;org.jboss.docs.cmp.cd.interfaces.CDHome&lt;/home&gt;
      &lt;remote&gt;org.jboss.docs.cmp.cd.interfaces.CD&lt;/remote&gt;
      &lt;ejb-class&gt;org.jboss.docs.cmp.cd.bean.CDBean&lt;/ejb-class&gt;
      &lt;persistence-type&gt;Container&lt;/persistence-type&gt;
      &lt;prim-key-class&gt;java.lang.Integer&lt;/prim-key-class&gt;
      &lt;reentrant&gt;False&lt;/reentrant&gt;
      &lt;cmp-field&gt;&lt;field-name&gt;id&lt;/field-name&gt;&lt;/cmp-field&gt;
      &lt;cmp-field&gt;&lt;field-name&gt;title&lt;/field-name&gt;&lt;/cmp-field&gt;
      &lt;cmp-field&gt;&lt;field-name&gt;artist&lt;/field-name&gt;&lt;/cmp-field&gt;
      &lt;cmp-field&gt;&lt;field-name&gt;type&lt;/field-name&gt;&lt;/cmp-field&gt;
      &lt;cmp-field&gt;&lt;field-name&gt;notes&lt;/field-name&gt;&lt;/cmp-field&gt;
      &lt;primkey-field&gt;id&lt;/primkey-field&gt;
    &lt;/entity&gt;

    &lt;session&gt;
      &lt;description&gt;Models a music CD collection&lt;/description&gt;
      &lt;ejb-name&gt;CDCollectionBean&lt;/ejb-name&gt;
      &lt;home&gt;org.jboss.docs.cmp.cd.interfaces.CDCollectionHome&lt;/home&gt;
      &lt;remote&gt;org.jboss.docs.cmp.cd.interfaces.CDCollection&lt;/remote&gt;
      &lt;ejb-class&gt;org.jboss.docs.cmp.cd.bean.CDCollectionBean&lt;/ejb-class&gt;
      &lt;session-type&gt;Stateless&lt;/session-type&gt;
      &lt;transaction-type&gt;Container&lt;/transaction-type&gt;
	  &lt;ejb-ref&gt;
         &lt;ejb-ref-name&gt;ejb/CD&lt;/ejb-ref-name&gt;
         &lt;ejb-ref-type&gt;Entity&lt;/ejb-ref-type&gt;
         &lt;home&gt;org.jboss.docs.cmp.cd.interfaces.CDHome&lt;/home&gt;
         &lt;remote&gt;org.jboss.docs.cmp.cd.interfaces.CD&lt;/remote&gt;
         &lt;ejb-link&gt;CDBean&lt;/ejb-link&gt;
	  &lt;/ejb-ref&gt;
    &lt;/session&gt;

  &lt;/enterprise-beans&gt;

  &lt;assembly-descriptor&gt;
    &lt;container-transaction&gt;
      &lt;method&gt;
        &lt;ejb-name&gt;CDBean&lt;/ejb-name&gt;
        &lt;method-name&gt;*&lt;/method-name&gt;
      &lt;/method&gt;
      &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;
    &lt;/container-transaction&gt;
  &lt;/assembly-descriptor&gt;
&lt;/ejb-jar&gt;
</pre><p>The first part of the listing above shows the section of ejb-jar.xml that 
is relevant to the CD Bean. It has the 
usual information about the classes that consitute the Bean, but it also 
specifies the type 
and name of the primary key, and the fields that are persistent. Note that in 
this case the 
"id" field gets listed twice: once as a persistent field and then again as the 
primary key field. 
It might be thought that specifying a field as a primary key would 
automatically make it persistent,
but it doesn't. </p><p>The second part of the listing is for the CDCollection session bean.  
It does not require any 
persistence information, 
but it does require an ejb-ref section; this indicates that the CDCollection 
Bean refers to CD Bean 
instances. The ejb-ref section lists the type of the CD Bean, and all its 
classes. </p><p>In the JBoss run-time configuration file "jboss.xml" we should specify the 
JNDI names of the 
Beans, like this:</p><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;jboss&gt;
    &lt;secure&gt;false&lt;/secure&gt;
    &lt;container-configurations /&gt;
    &lt;resource-managers /&gt;
    &lt;enterprise-beans&gt;
        &lt;session&gt;
	    &lt;ejb-name&gt;CDCollectionBean&lt;/ejb-name&gt;
	    &lt;jndi-name&gt;cd/CDCollection&lt;/jndi-name&gt;
	    &lt;configuration-name&gt;&lt;/configuration-name&gt;
        &lt;/session&gt;
        &lt;entity&gt;
	    &lt;ejb-name&gt;CDBean&lt;/ejb-name&gt;
	    &lt;jndi-name&gt;cd/CD&lt;/jndi-name&gt;
	    &lt;configuration-name&gt;&lt;/configuration-name&gt;
        &lt;/entity&gt;
    &lt;/enterprise-beans&gt;
&lt;/jboss&gt;

</pre><p>This says the "CDBean" has the JNDI name "cd/CD" and "CDCollectionBean" has 
the JNDI name "cd/CDCollection". </p><p>To compile and package the EJBs, run "ant cmp-cd-compile".  It compiles the sources
and create an EJB jar file ready for deployment.</p><p>During deployment (simply copy "documentation-example/build-examples/cmp-cd/ejb/cd.jar" to the
"deploy" subdirectory 
of the JBoss directory) you should see a message like the following:</p><pre class="programlisting">
<tt>
[Default] JBoss 2.2.2 Started in 0m:5s
[Auto deploy] Auto deploy of file:/C:/Projects/jbosscvs22/jboss/dist/deploy/cd.jar
[J2EE Deployer Default] Deploy J2EE application: file:/C:/Projects/jbosscvs22/jboss/dist/deploy/cd.jar
[J2EE Deployer Default] Create application cd.jar
[J2EE Deployer Default] install module cd.jar
[Container factory] Deploying:file:/C:/Projects/jbosscvs22/jboss/dist/tmp/deploy/Default/cd.jar
[Verifier] Verifying file:/C:/Projects/jbosscvs22/jboss/dist/tmp/deploy/Default/cd.jar/ejb1001.jar
[Container factory] Deploying CDBean
[Container factory] Deploying CDCollectionBean
[JAWS] Created table 'CDBean' successfully.
[Bean Cache] Cache policy scheduler started
[Container factory] Deployed application: file:/C:/Projects/jbosscvs22/jboss/dist/tmp/deploy/Default/cd.jar
[J2EE Deployer Default] J2EE application: file:/C:/Projects/jbosscvs22/jboss/dist/deploy/cd.jar is deployed.
</tt>
</pre><p>"JAWS" is the JBoss interface to the database engine. During deployment JAWS 
has 
deleted any existing table called "CDBean", then created a new CDBean table 
with 
the specified column layout. How does it know to use VARCHAR(256) for each 
field? 
It doesn't: it's guessing because we haven't provided any other information. 
During deployment, JAWS looks for a file called "jaws.xml"; if this file 
exists 
it is read to configure the names and geometry of the database tables. 
VARCHAR(256) is the default for String attributes. The default table name is 
the 
same as that of the Bean class, which is why we have ended up with a table 
called 
"CDBean". This also can be over-ridden in jaws.xml. In practice, the JAWS 
defaults 
are adequate during developement. However, there may be speed advantages to 
using fixed-length fields (e.g., CHAR(XX) rather than variable-length ones if 
at 
all possible.</p><p>Note that it can be very difficult to change the number or names of columns 
in the table once there is data in it. JBoss gets very confused by this, as 
you 
would expect. When a CMP Bean is re-deployed, JAWS tries to write into its 
table 
all the data it had in its last deployment. If the table has different columns 
it probably won't be able to do that. This means that it is important to get 
the 
persistent fields thoroughly correct before starting to put real data into the 
application.</p></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch05.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch05s08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s08.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch05s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch05s10.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -