乐观并发的设置:对于Weblogic700或以上的版本。
用Weblogic Builder打开你配备的jar文件,
展开你的实体bean,会有三个选项,Tuning,Methods,Resources。
选择Tuning,
然后在右侧窗口选择Cache页,
其中有叫Concurrency Strategy的下拉表,其中
Optimistic是乐观并发;
Exclusive是悲观并发(就是独占式访问)。

解决方案 »

  1.   

    通过JB配备成功后会把相应的jar文件拷贝到
    C:\bea\user_projects\mydomain\myserver\upload
    (如果user_projects是你的weblogic的user_projects目录)Weblogic Builder是weblogic自带的配备工具,在[开始]菜单中的[weblogic server]中可以启动。
    注:在JB7中没有设置实体并发控制的选项,以后的版本中是否支持我也不太清楚。
      

  2.   

    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!!
      

  3.   

    比如有两个表 
    CREATE TABLE books(
    INT id PRIMARY KEY,
    VCHAR(10) book_title,
    INT publisher_id FOREIGN KEY REFERENCE publishers.id
    )
    CREATE TABLE publishers(
    INT id PRIMARY KEY,
    VCHAR(10) pubisher_name
    )
    比如我想创建一条记录,通过输入books.id, book_title,publisher_name实现
    是不是要自己写一个ejbCreate方法?在方法里先找到publisher_name对应的出版商id,再把三条信息插入到books表中?cmr是container manage relationship.如果你想使用cmr,首先确定你必须是ejb2.0或者以上(有没有以上我也不知道)
    然后在ejb规范中cmr/cmp-field(即publisher_id )是不允许被操作的(不能用setXXX()方法),ejbcreat()里面也不能操作,也就是如果你的publicsher_id是not null,基本上你的程序就没法子运行了,至少Home.create()是甭想。
    再次你设置关联关系的时候不是setPublicherId( intValue),而是setPublishers( publishersObject)先A = AHome.create()
    然后B = BHome.create()
    再A.setB(B)