Hello,

I am having difficulty creating a container managed relationship.  I am using jboss 
3.2 on a windows machine.  

My ejb-jar.xml file relationship content is:
<!-- Relationships -->

  <ejb-relation >
  <ejb-relation-name>split-machines</ejb-relation-name>
     <ejb-relationship-role >          
<ejb-relationship-role-name>machine-belongs_to-split</ejb-relationship-role-name>
      < multiplicity >Many</ multiplicity >
       <cascade-delete/>
        <relationship-role-source >
            <ejb-name>Machine</ejb-name>
        </relationship-role-source>
        <cmr-field >
           <cmr-field-name>splitLocal</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >      
<ejb-relationship-role-name>splits-has-machines</ejb-relationship-role-name>
        < multiplicity >One</ multiplicity >
        <relationship-role-source >
          <ejb-name>Split</ejb-name>
        </relationship-role-source>
        <cmr-field >
          <cmr-field-name>machines</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
        </cmr-field>
      </ejb-relationship-role>
    </ejb-relation>
 

So what I'm trying to create is a bidirectional 1:N relationship b/w splits and 
machines.

In my SplitEJB file I have the following methods related to Machines: 
//Split class

  | 
  |    /**
  |     * 
  |     *    -generated May 26, 2004 11:26:34 AM
  |     * @param machineId
  |     * @param machineName
  |     * @ejb.interface-method 
  |     */
  |    public void addMachine(int machineId, String machineName) 
  |       throws FinderException, CreateException {
  |       try{
  |          MachineLocal machine = 
  |             MachineUtil.getLocalHome().create(machineId, machineName);
  |          getMachines().add(machine);
  |       } catch(NamingException e) {
  |          CreateException ce = new CreateException(e.getMessage());
  |          ce.initCause(e);
  |          throw ce;
  |       }
  |    }
  |    
  |    /**
  |     * 
  |     *    -generated May 26, 2004 11:31:45 AM
  |     * @return
  |     * @ejb.interface-method 
  |     */
  |    public Collection getAllMachineValues(){
  |       List machineValues = new ArrayList();
  |       for(Iterator iterator = getMachines().iterator(); iterator.hasNext(); ) {
  |          MachineLocal machine = (MachineLocal)iterator.next();
  |          machineValues.add(machine.getMachineValue());
  |       }
  |       
  |       return (Collection)machineValues;
  |    }
  |    
  |    /**
  |     * 
  |     *    -generated May 26, 2004 1:21:46 PM
  |     * @return
  |     * @ejb.interface-method 
  |     */
  |    public int getNumberOfMachines() {
  |       return getMachines().size();
  |    }
  | 
  |    /**
  |     * 
  |     *    -generated May 26, 2004 1:22:54 PM
  |     * @return
  |     * @ejb.interface-method 
  |     *    view-type = "local"
  |     * @ejb.relation 
  |     *    name = "split-machines"
  |     *    role-name = "splits-has-machines"
  |     *    
  |     */
  |    public abstract Collection getMachines();
  |    public abstract void setMachines(Collection machines);
  | 
  | // End Split class
  | 
  | The pertanent methods in the machine class are:
  | //Machine class
  |   /**
  |     * 
  |     *    -generated May 26, 2004 3:02:26 PM
  |     * @return
  |     * @ejb.persistence 
  |     *    column-name = "SPLIT_ID"
  |     *    
  |     */
  |    public abstract Integer getSplitId();
  |    public abstract void setSplitId(int splitId);   
  |    
  |    // -------------------------------------------
  |    // CMR (Container Managed Relationship) fields
  |    // -------------------------------------------
  |    
  |    /**
  |     * 
  |     *    -generated May 26, 2004 11:14:35 AM
  |     * @return
  |     * @ejb.interface-method 
  |     *    view-type = "local"
  |     * @ejb.relation 
  |     *    name = "split-machines"
  |     *    role-name = "machine-belongs_to-split"
  |     *    cascade-delete = "yes"
  |     * 
  |     * @jboss.relation 
  |     *    related-pk-field = "id"
  |     *    fk-column = "SPLIT_ID"
  |     *    fk-constraint = "true"
  |     */
  |    public abstract SplitLocal getSplitLocal();
  |    public abstract void setSplitLocal(Split split);
  |    
  |    /**
  |     * 
  |     *    -generated May 18, 2004 3:04:10 PM
  |     * @param id
  |     * @param name
  |     * @return
  |     * @throws CreateException
  |     * @ejb.create-method 
  |     */
  |    public Integer ejbCreate(int id, String name) throws CreateException {
  |       System.out.println("Creating Machine - id: " + id + " name: " + name);
  |       setId(new Integer(id));
  |       setName(name);
  |       return null;
  |    }
  | [/c[de]
  | //End Machine class
  | 
  | When I attempt to add machines to a split I get a Create exception saying that 
null cannot be passed into the foreign key (see machine create method), I was under 
the impression that the this would be taken care of by the Container managed 
persistence. 
  | 
  | Any light on how to assign a primary key to an entity bean would be very helpful.
  | 
  | Thanks

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3837303#3837303

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3837303



-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to