cmp-field and a cmr-field(Morgan_ma来接分)

lijing725 2003-10-31 03:29:43
如题!
...全文
107 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijing725 2003-10-31
  • 打赏
  • 举报
回复
you are right,i can create value into table as your way,but i have to set User table's fk allow to null.

are you read the code about weblogic's sample,it have tow table as follows:
CREATE TABLE bands (
name VARCHAR(50),
founder VARCHAR(50),
startDate date,
CONSTRAINT bands_pk PRIMARY KEY
(name, founder));

CREATE TABLE recordings (
title VARCHAR(50),
bandName VARCHAR(50),
bandFounder VARCHAR(50),
numberSold INT,
sales NUMERIC(10, 2),
recordingDate DATE,
CONSTRAINT recordings_pk PRIMARY KEY
(title, bandName, bandFounder),
CONSTRAINT recordings_fk FOREIGN KEY
(bandName, bandFounder)
REFERENCES bands(name, founder));

it use cmp to realize relationship,for fk name and founder it also use set**() method in record.create(*,*..),but it run success.

i always analysis why it run?

i agree you opinion that "When you use EJB relationships, you don't have to think only relational database but also Object Oriented database",use cmr need to think of concrete requirement.

thank you!
Morgan_ma 2003-10-31
  • 打赏
  • 举报
回复
It is the correct answer.I have tried myself.It is O.K.


Good Luck!
Morgan_ma 2003-10-31
  • 打赏
  • 举报
回复
OK then here is the thing:

When you use EJB relationships, you don't have to think only relational
database but also Object Oriented database. I mean you don't have to
store in an entityA field the PK of entityB but rather say to the
system, (in this case the EJB container) my entityA instance is linked
to this instance of entity B and the system (OO DB or the container is
taking care of the persistency of that specific instances' relation).

For example:
EntityA represents BANK's users (PK= String userID + String bankID)
EntityB represents BANKs (PK= String bankID). A Bank may have several
users within the bank.

Suppose you want to create a EJB relationship between users and banks.
So you create a CMR field in EntityA called rBank. This relationship
needs to be persisted so you specify in the deployment descriptor that
the relationship is related to the table Users, column field bankID
(which is, from a relational DB point of vue, a FOREIGN KEY). You need
to "tell" the container how it should persist the relationship. The DD
is there for that.

Of course you have that column represented in the entityA as a CMP field
(bankID) so you may (NOT AN OBLIGATION) have defined (your IDE may have
done that for you automatically) a SET method for that CMP field.

In EntityB you have a CMR field called rUsers for which the getRUsers
method return a Collection of EntityA instances. Again here, that CMR is
linked to the CMP field bankID in the table BANK for persistency
purposes.

Note: CMR fields like CMP fields can have getters and setters.

Now, you want to create a new user.

>From the EntityA home interface you use the create method which will
return you a new EntityA instance.
Within the ejbCreate method of EntityA you may initialise the
relationship with a bank's instance. You can't use the setBankID of
EntityA (THAT's THE RULE in the SPEC) but you need to ge the bank's
instance (findByPK) and apply the method:
instanceB.getRUsers().add(this). Of course I do not recommend to do that
there.. But rather in a SessionBean.


So in the session bean:

EntityA entityA = null;
EntityB entityB = null;
Try
{
entityA = entityAHome.create(new PK);
entityA.setXXX(...) for CMP fields not being part in a relation
(you can do the setter in the ejbCreate method).
entityA.setBankID(bankID); /// THIS WILL CAUSE AN EXCEPTION
entityB = entityBHome.findByPK(bankID);
entityB.getRUsers().add(entityA); //here the container will
update CMP field bankID in entityA with the right info based on the info
provided in the deployment descriptor). }

Note: I'd recommend you not to provide any setters for CMP-CMR fields to
avoid any tentation!!
Note: in the case of a N-M table relationship, you need to have a
intermediate table (typical database technique) and CMR fields in
entnityA/B needs to be "physically" linked (in the DD) to that
intermediary table.
内容概要:本文详细介绍了利用Simulink进行变压器开路试验的电路连接配置与仿真实现方法,重点在于通过仿真手段还原实际电力系统中变压器在空载条件下的电气特性,从而深入理解其工作原理与性能表现。文章作为电力系统仿真系列研究的一部分,系统阐述了从电路模型搭建、参数设定、仿真运行到结果分析的完整流程,突出展示了MATLAB/Simulink在电力设备建模与教学科研中的强大功能与应用价值。; 适合人群:具备电力系统基础知识,熟悉MATLAB/Simulink仿真环境,从事电气工程、自动化及相关领域的研发人员,以及高年级本科生和研究生。; 使用场景及目标:①掌握变压器开路试验的基本原理与Simulink仿真建模的具体步骤;②通过仿真实验深入理解空载电流、铁芯损耗及励磁特性等关键参数的物理意义;③为后续开展变压器短路试验、暂态过程分析以及其他电力设备的仿真研究奠定理论与实践基础。; 阅读建议:建议结合Simulink软件动手实践,逐步构建并调试电路模型,重点关注各元件参数的设置方法与测量模块的应用技巧,同时推荐参考文中提及的其他相关仿真案例进行拓展学习,以全面提升对电力系统仿真实践的整体认知与操作能力。

67,536

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧