新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Java, J2SE, J2ME, J2EE, 以及Eclipse, NetBeans, JBuilder等Java开发环境,还有JSP, JavaServlet, JavaBean, EJB以及struts, hibernate, spring, webwork2, Java 3D, JOGL等相关技术。
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Java/Eclipse 』 → 问题解决了 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6658 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 问题解决了 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     admin 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      头衔:W3China站长
      等级:计算机硕士学位(管理员)
      文章:5255
      积分:18406
      门派:W3CHINA.ORG
      注册:2003/10/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给admin发送一个短消息 把admin加入好友 查看admin的个人资料 搜索admin在『 Java/Eclipse 』的所有贴子 点击这里发送电邮给admin  访问admin的主页 引用回复这个贴子 回复这个贴子 查看admin的博客楼主
    发贴心情 问题解决了

    ● 问题解决了发信人: lywater (雨燕), 信区: J2EE
    标  题: 问题解决了
    发信站: BBS 水木清华站 (Mon May 17 21:04:53 2004), 站内

    偶在csdn上找了一个晚上,终于找到答案了
    现向大家共享之,好东东,大家共享啊^_^

    ------------------------------------

    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);
    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.
    【 在 itisuptome (马不停蹄) 的大作中提到: 】                                    
    : 解决这个问题有简单方法                                                        
    : 将出问题的这个属性项设为主键(cmp的主键,数据库是不是没关系)                 
    : 这样就没问题了                                                                
    : ...................

    --
    family中F是father,A是and,M是mother,I是i,L是love,Y是you.
    于是,FAMILY就是:father and mother,i love you!


    ※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.195.*]                        

    索引页面|上一篇|下一篇


       收藏   分享  
    顶(0)
      




    ----------------------------------------------

    -----------------------------------------------

    第十二章第一节《用ROR创建面向资源的服务》
    第十二章第二节《用Restlet创建面向资源的服务》
    第三章《REST式服务有什么不同》
    InfoQ SOA首席编辑胡键评《RESTful Web Services中文版》
    [InfoQ文章]解答有关REST的十点疑惑

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/9/23 0:40:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Java/Eclipse 』的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/30 7:07:27

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    7,082.031ms