求教精通ejb规范的高手,关于Dependent Value Classes的疑问

在ejb2.1规范的第147页下面,
A dependent value class is a concrete class that is the value of cmp-field. A dependent value class may be a class that the Bean Provider wishes to use internally within an entity bean with container-managed persistence, and/or it may be a class that the Bean Provider chooses to expose through the remote (or local) interface of the entity bean.

A dependent value class can be the value of a cmp-field; it cannot be the value of a cmr-field.

The get accessor method for a cmp-field that corresponds to a dependent value class returns a copy of the dependent value class instance. The assignment of a dependent value class value to a cmp-field using the set accessor method causes the value to be copied to the target cmp-field.

A dependent value class must be serializable. The internal structure of a dependent value class is not described in the EJB deployment descriptor.

最让我看不懂的就是第3段,怎么会是拷贝传的参数呢,本地客户试图的方法不都是pass by reference的么?Dependent Value Class又是什么东西呢,好像从没有听说过。

什么是entity,什么是value,这是个问题

并不是所有的class都是entity,也不要把所有的table都认为是entity。当然这样做了也没什么影响。

一个entity是独立于其它entity的,有自己的生命周期,如果一个class是另外一个class的一部分,或者一个class生命周期完全依赖于另外一个class,那么这个class其实并不是entity,而是dependent value class,sun白皮书里面是helper class;hibernate里面叫component。

举个j2ee tutorial 里面的例子P954 pdf页996,Order 和 LineItem,这个例子是相当典型的,在hibernate里面也作为例子,hibernate doc v2.1.6 P58.不过hibernate的有所扩充,更为强大。

public class LineItem implements java.io.Serializable {
String productId;
int quantity;
double unitPrice;
int itemNo;
String orderId;

}
一个Order肯定有若干LineItem,而Order没有了,这份Order里面的LineItem也失去意义了,所有LineItem生命周期完全依赖于Order,她是一个dependent value class。她具有值的语意。

对于entity 当然pass by reference。对于value是pass by copy

基本赞同napoleonn 的解释,但是napoleonn 的举例是普通的POJO,在实体Bean中表现中还是有些区别。

我习惯把数据分成两种类型:实体和关系;
实体就是独立的,在业务需求中能够代表一类事物数据的东东,是实在的东西,所以简称为实体,实体Bean有几种实现,CMP是代表;

关系是用来说明类图的一对多等关系的,在实体Bean中使用CMR来表示。

在实体Bean中,有时没有主键,这时需要生成一个外部主键类,如UserPK之类,这个类应该是典型的Dependent Value Classes。