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

📄 ch06s14.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Dependant Value Objects [since JBoss 2.4]</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="ch06.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06.html" title="Chapter 6. Customizing JAWS"><link rel="previous" href="ch06s13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06s13.html" title="Defining a type mapping"><link rel="next" href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.html" title="Chapter 7. Advanced container configuration : use of jboss.xml"></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="ch06.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch06s13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06s13.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.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="d0e2416"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e2416"></a>Dependant Value Objects [since JBoss 2.4]</h2></div></div><p>Author: 
            <span class="author">Vincent Harcq</span>
            <tt>&lt;<a href="mailto:vincent.harcq@hubmethods.com">vincent.harcq@hubmethods.com</a>&gt;</tt>
         </p><p>Standards compliance note: this feature is not standard or required in EJB 1.1. Therefore, EJBs that 
use this feature, might not be compile-free portable to other EJB containers.</p><p>JAWS store non primitive type fields as Object in the database.  When the field is a JavaBean, an object with 
      some primitive type attributes with getter/setter accessing methods, it is possible to store the value of these attributes
instead of the whole object.</p><p>For example suppose in the Class bean, we have a field "lesson" representing the subject (english, mathematics,..)
and the number of hours that the teacher take to give its lesson.  This field is an simple JavaBean:</p><pre class="programlisting">
package org.jboss.docs.cmp.jaws.interfaces;

import java.io.Serializable;

public class LessonDetail
implements Serializable{

   private String subject;
   private Integer hours;

   public String getSubject(){ return subject; }
   public void setSubject(String subject){ this.subject = subject; }

   public Integer getHours(){ return hours; }
   public void setHours(Integer hours){ this.hours = hours; }

}
</pre><p>The ejb-jar.xml will still define "lesson" as the CMP field:</p><pre class="programlisting">
&lt;ejb-jar&gt;
  &lt;display-name&gt;Class&lt;/display-name&gt;
  &lt;enterprise-beans&gt;
    &lt;entity&gt;
      ...
	  &lt;cmp-field&gt;&lt;field-name&gt;lesson&lt;/field-name&gt;&lt;/cmp-field&gt;
	  ...
    &lt;/entity&gt;
  &lt;/enterprise-beans&gt;
&lt;/ejb-jar&gt;

</pre><p>But jaws.xml will say how to store/retrieve
the object:</p><pre class="programlisting">
&lt;jaws&gt;
	&lt;enterprise-beans&gt;
		&lt;entity&gt;
			...
			&lt;cmp-field&gt;
				&lt;field-name&gt;lesson.subject&lt;/field-name&gt;
				&lt;column-name&gt;LESSON_SUBJECT&lt;/column-name&gt;
			&lt;/cmp-field&gt;
			&lt;cmp-field&gt;
				&lt;field-name&gt;lesson.hours&lt;/field-name&gt;
				&lt;column-name&gt;HOURS&lt;/column-name&gt;
			&lt;/cmp-field&gt;
			...
		&lt;/entity&gt;
	&lt;/enterprise-beans&gt;
&lt;/jaws&gt;
</pre><p>Two database fields are now used to store the "value" of the object.  The trick is to have getter/setter method
corresponding to what you have to store/retrieve.</p><p>This feature is recursive, so you can have something like lesson.subject.name, lesson.subject.group,...</p><p>Notice that if the dependant object defines its attributes as "public", the getter/setter methods are not necessary.
This can be used in an entity bean to store a reference to another entity bean by its Primary Key object.  Indeed, in
this case, the primary key fields are declared as public in the PK class.</p><p>Finally notice that even if this a non standard requirement in EJB 1.1, there is a way to program this in a standard way.
This is to define the 2 CMP fields in the bean and access them through getter/setter method of "LessonDetail" type.
These will map the database fields to the object and vice versa.  A more performant solution is to keep a private "LessonDetail"
attribute in the bean that is construct in the ejbLoad() method.</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="ch06.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch06s13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch06s13.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.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 + -