新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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 』 → [合集] CMP用CMR时遇到的问题 查看新帖用户列表

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

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

    ● [合集] CMP用CMR时遇到的问题发信人: petbear (雨中的人), 信区: J2EE
    标  题: [合集] CMP用CMR时遇到的问题
    发信站: BBS 水木清华站 (Tue May 18 00:01:52 2004), 站内

    ☆─────────────────────────────────────☆  
      lywater (雨燕) 于  (Sun May 16 21:19:37 2004)  提到:

    两个表:UserLoginInfo,UserType
    UserLoginInfo里存储用户的信息,又一个字段userTypeID存放用户的类别编号
    UserType存放用户类别信息,同样有一个字段userTypeID,设为主键
    在jb9中,将两者关联,UserLoginInfo(n)--》(1)UserType,单向

    调用过程jsp-servlet-sessionBean-EntityBean
    新增一个用户,也就是向UserLoginInfo中插入一条记录
    结果报错:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exception
    is: javax.ejb.EJBException: [EJB:010145]When a cmp-field and a cmr-field (relati
    onship) are mapped to the same column, the setXXX method for the cmp-field may
    not be called. The cmp-field is read-only.

    javax.ejb.EJBException: [EJB:010145]When a cmp-field and a cmr-field (relationsh
    ip) are mapped to the same column, the setXXX method for the cmp-field may not
    be called. The cmp-field is read-only.

    同样的语句,同样的方法,要是去掉cmr关系,可以正常运用
    这是怎么回事?


    ☆─────────────────────────────────────☆  
    lywater (雨燕) 于  (Sun May 16 21:53:25 2004)  提到:

    用了精华区里的方法
    可是,错误一样。。。。。

    【 在 lywater (雨燕) 的大作中提到: 】                                           
    : 两个表:UserLoginInfo,UserType                                               
    : UserLoginInfo里存储用户的信息,又一个字段userTypeID存放用户的类别编号         
    : UserType存放用户类别信息,同样有一个字段userTypeID,设为主键                  
    : ...................                                                           



    ☆─────────────────────────────────────☆  
    diaochong (静静的雕虫~~小猪) 于  (Mon May 17 08:46:45 2004)  提到:


    插记录的时候两个表中所有必须非空的字段都要照顾到

    【 在 lywater (雨燕) 的大作中提到: 】                                           
    : 两个表:UserLoginInfo,UserType                                               
    : UserLoginInfo里存储用户的信息,又一个字段userTypeID存放用户的类别编号         
    : UserType存放用户类别信息,同样有一个字段userTypeID,设为主键                  
    : ...................



    ☆─────────────────────────────────────☆  
    lywater (雨燕) 于  (Mon May 17 12:10:45 2004)  提到:

    我的第二张表是固定的啊
    只有量个字段--用户类别编号(pk),用户类别名
    在这张表里不存在增、删、查、改的操作

    【 在 diaochong (静静的雕虫~~小猪) 的大作中提到: 】                             
    : 插记录的时候两个表中所有必须非空的字段都要照顾到                              




    ☆─────────────────────────────────────☆  
    lywater (雨燕) 于  (Mon May 17 12:14:28 2004)  提到:

    下面是精华区中的一篇贴子,还是有些不明白的地方,请高人指点,谢谢

    发信人: zdragon (Dragon), 信区: Java
    标  题: 关于CMP Relation 的一点学习心得
    发信站: BBS 水木清华站 (Tue Apr 22 14:03:35 2003), 转信

    环境:Weblogic 6.1 sp1
    TOols: Jbuilder 8

    问题说明:

      两个表映射为CMP: Docs and Types
      有 many-1 的关系

      Docs ----- docId(PK),typeId(Foreign Key)

      Types ---- typeId(PK),typeName


    出现问题原因:

        过于依赖Jbuilder,没有仔细阅读EJB文档

    出现症状:

        数据时,出现Exception:

      create(docId,typeId)
      
      抛出 exception :

        javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship)
    are
        mapped to the same column, the setXXX method for the cmp-field may not b
    e
        called.  The cmp-field is read-only.

    解决办法:

        修改Bean代码,将ejbCreate(xxxx.....)中的setFK字段去掉

      在ejbPostCreate(xxxx......)中加入

            setType(type);
            ~~~~~~~~~请问,这里set的是fk字段,还是别的什么东东?
                              fk我试过了,不行,错误一样的:(

    其他说明: 也许只有我才会遇到这样的问题!:~(




    ☆─────────────────────────────────────☆  
    itisuptome (马不停蹄) 于  (Mon May 17 19:24:09 2004)  提到:

    解决这个问题有简单方法
    将出问题的这个属性项设为主键(cmp的主键,数据库是不是没关系)
    这样就没问题了

    【 在 lywater (雨燕) 的大作中提到: 】                                           
    : 下面是精华区中的一篇贴子,还是有些不明白的地方,请高人指点,谢谢              
    : 发信人: zdragon (Dragon), 信区: Java                                          
    : 标  题: 关于CMP Relation 的一点学习心得                                       
    : ...................                                                           



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

    ☆─────────────────────────────────────☆  
      lywater (雨燕) 于  (Mon May 17 21:09:28 2004)  提到:

    感觉比精华区里的方法好
    说句实话,精华区里的那种方法,看后感觉要想从外面传参数的话比较困难
    而这种方法还是比较灵活的

    同时感谢各位网友的帮助
    呵呵,以后有什么好东东,大家表忘了共享哦。。。。。

    【 在 lywater (雨燕) 的大作中提到: 】                                           
    : 偶在csdn上找了一个晚上,终于找到答案了                                        
    : 现向大家共享之,好东东,大家共享啊^_^                                         
    : ------------------------------------      
    : ...................                                                           

    记下来了
    等以后有时间了慢慢的研究
    当前的任务是,赶快写作业。。。。
    不论用什么方法,一定要在deadline之前把作业搞定的^_^
    【 在 itisuptome (马不停蹄) 的大作中提到: 】                                    
    : 解决这个问题有简单方法                                                        
    : 将出问题的这个属性项设为主键(cmp的主键,数据库是不是没关系)                 
    : 这样就没问题了                                                                
    : ...................                                                           


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


       收藏   分享  
    顶(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 4:39:28

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

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