📄 ch06s14.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><<a href="mailto:vincent.harcq@hubmethods.com">vincent.harcq@hubmethods.com</a>></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">
<ejb-jar>
<display-name>Class</display-name>
<enterprise-beans>
<entity>
...
<cmp-field><field-name>lesson</field-name></cmp-field>
...
</entity>
</enterprise-beans>
</ejb-jar>
</pre><p>But jaws.xml will say how to store/retrieve
the object:</p><pre class="programlisting">
<jaws>
<enterprise-beans>
<entity>
...
<cmp-field>
<field-name>lesson.subject</field-name>
<column-name>LESSON_SUBJECT</column-name>
</cmp-field>
<cmp-field>
<field-name>lesson.hours</field-name>
<column-name>HOURS</column-name>
</cmp-field>
...
</entity>
</enterprise-beans>
</jaws>
</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 + -